Create Version Tag #141
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Create Version Tag | |
| on: | |
| workflow_run: | |
| workflows: ["Build"] | |
| types: [completed] | |
| branches: [main] | |
| permissions: | |
| contents: write | |
| jobs: | |
| create-tag: | |
| if: github.event.workflow_run.conclusion == 'success' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Extract version | |
| id: version | |
| run: | | |
| VERSION=$(sed -n 's/.*"version": "\([^"]*\)".*/\1/p' sources.json | head -1) | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| echo "major=${VERSION%%.*}" >> "$GITHUB_OUTPUT" | |
| - name: Check if version tag exists | |
| id: check-tag | |
| run: | | |
| if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then | |
| echo "exists=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "exists=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Configure git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Create version tag | |
| if: steps.check-tag.outputs.exists == 'false' | |
| run: | | |
| git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}" | |
| git push origin "v${{ steps.version.outputs.version }}" | |
| - name: Update moving tags | |
| if: steps.check-tag.outputs.exists == 'false' | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| MAJOR="${{ steps.version.outputs.major }}" | |
| git push origin :refs/tags/latest 2>/dev/null || true | |
| git push origin ":refs/tags/v$MAJOR" 2>/dev/null || true | |
| git tag -d latest 2>/dev/null || true | |
| git tag -d "v$MAJOR" 2>/dev/null || true | |
| git tag -a latest -m "Latest release: v$VERSION" | |
| git tag -a "v$MAJOR" -m "Latest v$MAJOR release: v$VERSION" | |
| git push origin latest "v$MAJOR" | |
| - name: Summary | |
| run: | | |
| echo "## Tag Summary" >> "$GITHUB_STEP_SUMMARY" | |
| echo "" >> "$GITHUB_STEP_SUMMARY" | |
| echo "| Tag | Points To |" >> "$GITHUB_STEP_SUMMARY" | |
| echo "| --- | --- |" >> "$GITHUB_STEP_SUMMARY" | |
| if [ "${{ steps.check-tag.outputs.exists }}" = "false" ]; then | |
| echo "| v${{ steps.version.outputs.version }} | $(git rev-parse --short HEAD) |" >> "$GITHUB_STEP_SUMMARY" | |
| echo "| v${{ steps.version.outputs.major }} | v${{ steps.version.outputs.version }} |" >> "$GITHUB_STEP_SUMMARY" | |
| echo "| latest | v${{ steps.version.outputs.version }} |" >> "$GITHUB_STEP_SUMMARY" | |
| else | |
| echo "| v${{ steps.version.outputs.version }} | unchanged (already existed) |" >> "$GITHUB_STEP_SUMMARY" | |
| echo "| v${{ steps.version.outputs.major }} | unchanged |" >> "$GITHUB_STEP_SUMMARY" | |
| echo "| latest | unchanged |" >> "$GITHUB_STEP_SUMMARY" | |
| fi |