ci: GH-3 Part 4 - Using example release workflow #4
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: Publish Changesets | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: write | |
| jobs: | |
| check-outdated: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| has_outdated: ${{ steps.check_publish.outputs.has_outdated }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Setup Go | |
| uses: actions/setup-go@v6 | |
| with: | |
| go-version-file: go.mod | |
| - name: Install tools | |
| run: go install tool | |
| - name: Check for outdated versions | |
| id: check_publish | |
| run: | | |
| # Check if any projects have version.txt > git tag | |
| # Use a test command to check if filter returns any projects | |
| if changeset each --filter outdated-versions -- echo "found" 2>/dev/null | grep -q "found"; then | |
| echo "has_outdated=true" >> $GITHUB_OUTPUT | |
| echo "Outdated projects found" | |
| else | |
| echo "has_outdated=false" >> $GITHUB_OUTPUT | |
| echo "No projects to publish" | |
| fi | |
| publish: | |
| runs-on: ubuntu-latest | |
| needs: check-outdated | |
| if: needs.check-outdated.outputs.has_outdated == 'true' | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Setup Go | |
| uses: actions/setup-go@v6 | |
| with: | |
| go-version-file: go.mod | |
| - name: Install tools | |
| run: go install tool | |
| - name: Configure Git Credentials | |
| run: | | |
| git config user.name github-actions[bot] | |
| git config user.email github-actions[bot]@users.noreply.github.com | |
| - name: Publish tags and GitHub release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| REPO_OWNER: ${{ github.repository_owner }} | |
| REPO_NAME: ${{ github.event.repository.name }} | |
| run: | | |
| changeset each --filter outdated-versions -- \ | |
| changeset publish --owner "$REPO_OWNER" --repo "$REPO_NAME" |