Release application #999
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: Release application | |
| on: | |
| workflow_run: | |
| workflows: ["Publish Github Pages"] | |
| types: | |
| - completed | |
| branches: | |
| - main | |
| push: | |
| tags: | |
| - "v*.*.*" | |
| pull_request: | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| if: | | |
| github.event.workflow_run.conclusion == 'success' || | |
| github.event_name == 'push' || | |
| github.event_name == 'pull_request' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 # Fetch full history for tags comparison | |
| - name: Get latest gh-pages commit | |
| id: latest-gh-pages | |
| run: | | |
| GH_PAGES_COMMIT=$(git ls-remote origin refs/heads/gh-pages | cut -f1) | |
| echo "gh_pages_commit=$GH_PAGES_COMMIT" >> $GITHUB_OUTPUT | |
| - name: Get last gh-pages commit from last release notes | |
| id: last-gh-pages | |
| run: | | |
| LAST_RELEASE_TAG=$(git describe --tags --abbrev=0 --match "v*" || echo "") | |
| if [ -z "$LAST_RELEASE_TAG" ]; then | |
| echo "No previous tag found." | |
| echo "commit=" >> $GITHUB_OUTPUT | |
| else | |
| GH_PAGES_COMMIT=$(git tag -l --format='%(contents)' "$LAST_RELEASE_TAG" | grep "gh-pages-commit:" | cut -d':' -f2 | xargs) | |
| echo "commit=$GH_PAGES_COMMIT" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Compare gh-pages commits | |
| id: check-changes | |
| run: | | |
| echo "Latest gh-pages commit: ${{ steps.latest-gh-pages.outputs.gh_pages_commit }}" | |
| echo "Last released gh-pages commit: ${{ steps.last-gh-pages.outputs.commit }}" | |
| if [ "${{ steps.latest-gh-pages.outputs.gh_pages_commit }}" != "${{ steps.last-gh-pages.outputs.commit }}" ]; then | |
| echo "has_changes=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "has_changes=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Exit if no changes detected | |
| if: steps.check-changes.outputs.has_changes == 'false' | |
| run: | | |
| echo "No changes detected in gh-pages, skipping release." | |
| exit 0 | |
| - name: Clone gh-pages content | |
| run: | | |
| rm -rf app/desktop/content | |
| git clone --branch gh-pages --single-branch --depth 1 https://github.com/GoFarsi/book.git app/desktop/content | |
| - name: Setup Go | |
| uses: actions/setup-go@v3 | |
| with: | |
| go-version: '1.24' | |
| - name: Generate version | |
| id: version | |
| run: | | |
| chmod +x scripts/version.sh | |
| VERSION=$(./scripts/version.sh) | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Generated version: $VERSION" | |
| - name: Create git tag including gh-pages commit SHA | |
| if: | | |
| steps.check-changes.outputs.has_changes == 'true' && | |
| !contains(github.ref, 'tags/v') | |
| run: | | |
| git config user.name github-actions | |
| git config user.email [email protected] | |
| git tag -a "${{ steps.version.outputs.version }}" -m "Auto-generated release ${{ steps.version.outputs.version }} | |
| gh-pages-commit: ${{ steps.latest-gh-pages.outputs.gh_pages_commit }}" | |
| git push origin "${{ steps.version.outputs.version }}" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Run GoReleaser | |
| if: steps.check-changes.outputs.has_changes == 'true' | |
| uses: goreleaser/goreleaser-action@v6 | |
| with: | |
| version: latest | |
| args: release --clean | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |