|
| 1 | +name: Update Major Version Tag |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v[0-9]+.[0-9]+.[0-9]+' |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + tag: |
| 10 | + description: 'The full version tag to process (e.g., v13.1.0)' |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + |
| 14 | +jobs: |
| 15 | + update-major-tag: |
| 16 | + name: Update Major Version Tag |
| 17 | + runs-on: ubuntu-latest |
| 18 | + permissions: |
| 19 | + contents: write |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + |
| 26 | + - name: Get tag name |
| 27 | + id: get-tag |
| 28 | + run: | |
| 29 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 30 | + TAG="${{ inputs.tag }}" |
| 31 | + else |
| 32 | + TAG="${GITHUB_REF#refs/tags/}" |
| 33 | + fi |
| 34 | + echo "tag=$TAG" >> $GITHUB_OUTPUT |
| 35 | + # Extract major version (e.g., v13 from v13.1.0) |
| 36 | + MAJOR_TAG=$(echo "$TAG" | sed -E 's/^(v[0-9]+)\..*/\1/') |
| 37 | + echo "major_tag=$MAJOR_TAG" >> $GITHUB_OUTPUT |
| 38 | +
|
| 39 | + - name: Update major version tag |
| 40 | + run: | |
| 41 | + TAG="${{ steps.get-tag.outputs.tag }}" |
| 42 | + MAJOR_TAG="${{ steps.get-tag.outputs.major_tag }}" |
| 43 | + |
| 44 | + echo "Processing tag: $TAG" |
| 45 | + echo "Major version tag: $MAJOR_TAG" |
| 46 | + |
| 47 | + # Configure git |
| 48 | + git config user.name "github-actions[bot]" |
| 49 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 50 | + |
| 51 | + # Get the commit SHA for the pushed tag |
| 52 | + COMMIT_SHA=$(git rev-list -n 1 "$TAG") |
| 53 | + echo "Commit SHA: $COMMIT_SHA" |
| 54 | + |
| 55 | + # Delete the major tag locally if it exists |
| 56 | + git tag -d "$MAJOR_TAG" 2>/dev/null || true |
| 57 | + |
| 58 | + # Create/update the major version tag pointing to the same commit |
| 59 | + git tag "$MAJOR_TAG" "$COMMIT_SHA" |
| 60 | + |
| 61 | + # Force push the major version tag to origin |
| 62 | + git push origin "$MAJOR_TAG" --force |
| 63 | + |
| 64 | + echo "Successfully updated $MAJOR_TAG to point to $TAG ($COMMIT_SHA)" |
0 commit comments