|
| 1 | +# This workflow updates the MAD-NG version across the repository |
| 2 | +# It updates the version in workflows, test inputs, and changelog |
| 3 | + |
| 4 | +name: Bump MAD-NG release |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + new_version: |
| 10 | + description: 'New MAD-NG version (e.g., 1.1.7)' |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + major_minor: |
| 14 | + description: 'Major.minor version for URL path (e.g., 1.1)' |
| 15 | + required: true |
| 16 | + type: string |
| 17 | + changelog_entry: |
| 18 | + description: 'Changelog entry for this update (optional)' |
| 19 | + required: false |
| 20 | + type: string |
| 21 | + default: '' |
| 22 | + |
| 23 | +permissions: |
| 24 | + contents: write |
| 25 | + pull-requests: write |
| 26 | + |
| 27 | +jobs: |
| 28 | + bump-version: |
| 29 | + runs-on: ubuntu-latest |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v5 |
| 32 | + |
| 33 | + - name: Validate inputs |
| 34 | + run: | |
| 35 | + # Validate new_version format (semver: x.y.z) |
| 36 | + if ! echo "${{ inputs.new_version }}" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then |
| 37 | + echo "Error: new_version must be in semver format (e.g., 1.1.7)" |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | + # Validate major_minor format (x.y) |
| 41 | + if ! echo "${{ inputs.major_minor }}" | grep -qE '^[0-9]+\.[0-9]+$'; then |
| 42 | + echo "Error: major_minor must be in x.y format (e.g., 1.1)" |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | + echo "Inputs validated successfully" |
| 46 | +
|
| 47 | + - name: Get current version |
| 48 | + id: current |
| 49 | + run: | |
| 50 | + # Extract current version from test-pymadng.yml |
| 51 | + CURRENT_VERSION=$(grep -oP 'mad-linux-\K[0-9]+\.[0-9]+\.[0-9]+' .github/workflows/test-pymadng.yml | head -1) |
| 52 | + CURRENT_MAJOR_MINOR=$(grep -oP 'releases/madng/\K[0-9]+\.[0-9]+' .github/workflows/test-pymadng.yml | head -1) |
| 53 | + |
| 54 | + # Validate extracted versions |
| 55 | + if [ -z "$CURRENT_VERSION" ] || [ -z "$CURRENT_MAJOR_MINOR" ]; then |
| 56 | + echo "Error: Could not extract current version from test-pymadng.yml" |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | + |
| 60 | + echo "version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT" |
| 61 | + echo "major_minor=$CURRENT_MAJOR_MINOR" >> "$GITHUB_OUTPUT" |
| 62 | + echo "Current MAD-NG version: $CURRENT_VERSION" |
| 63 | + echo "Current major.minor: $CURRENT_MAJOR_MINOR" |
| 64 | +
|
| 65 | + - name: Update workflow files |
| 66 | + run: | |
| 67 | + # Update both workflow files with the new MAD-NG version |
| 68 | + for workflow in test-pymadng.yml python-publish.yml; do |
| 69 | + sed -i "s|releases/madng/${{ steps.current.outputs.major_minor }}/mad-linux-${{ steps.current.outputs.version }}|releases/madng/${{ inputs.major_minor }}/mad-linux-${{ inputs.new_version }}|g" ".github/workflows/$workflow" |
| 70 | + sed -i "s|releases/madng/${{ steps.current.outputs.major_minor }}/mad-macos-${{ steps.current.outputs.version }}|releases/madng/${{ inputs.major_minor }}/mad-macos-${{ inputs.new_version }}|g" ".github/workflows/$workflow" |
| 71 | + echo "Updated $workflow" |
| 72 | + done |
| 73 | +
|
| 74 | + - name: Update example.log |
| 75 | + run: | |
| 76 | + sed -i "s/\[${{ steps.current.outputs.version }}\]/[${{ inputs.new_version }}]/g" tests/inputs/example.log |
| 77 | + echo "Updated example.log" |
| 78 | +
|
| 79 | + - name: Update CHANGELOG.md |
| 80 | + run: | |
| 81 | + CHANGELOG_ENTRY="${{ inputs.changelog_entry }}" |
| 82 | + if [ -z "$CHANGELOG_ENTRY" ]; then |
| 83 | + CHANGELOG_ENTRY="Update to MAD-NG ${{ inputs.new_version }}" |
| 84 | + fi |
| 85 | + |
| 86 | + # Get current date in YYYY/MM/DD format |
| 87 | + CURRENT_DATE=$(date +%Y/%m/%d) |
| 88 | + |
| 89 | + # Prepend new version entry to CHANGELOG.md with proper format |
| 90 | + TEMP_FILE=$(mktemp) |
| 91 | + echo "$CHANGELOG_ENTRY ($CURRENT_DATE)" > "$TEMP_FILE" |
| 92 | + echo "" >> "$TEMP_FILE" |
| 93 | + cat CHANGELOG.md >> "$TEMP_FILE" |
| 94 | + mv "$TEMP_FILE" CHANGELOG.md |
| 95 | + echo "Updated CHANGELOG.md" |
| 96 | +
|
| 97 | + - name: Create Pull Request |
| 98 | + uses: peter-evans/create-pull-request@v7 |
| 99 | + with: |
| 100 | + commit-message: "Bump MAD-NG version to ${{ inputs.new_version }}" |
| 101 | + title: "Bump MAD-NG version to ${{ inputs.new_version }}" |
| 102 | + body: | |
| 103 | + This PR updates the MAD-NG version from ${{ steps.current.outputs.version }} to ${{ inputs.new_version }}. |
| 104 | +
|
| 105 | + ## Changes |
| 106 | + - Updated `.github/workflows/test-pymadng.yml` |
| 107 | + - Updated `.github/workflows/python-publish.yml` |
| 108 | + - Updated `tests/inputs/example.log` |
| 109 | + - Updated `CHANGELOG.md` |
| 110 | +
|
| 111 | + ## MAD-NG Release |
| 112 | + New version: ${{ inputs.new_version }} |
| 113 | + Major.minor: ${{ inputs.major_minor }} |
| 114 | + branch: bump-madng-${{ inputs.new_version }} |
| 115 | + base: main |
0 commit comments