feat: add script to dynamically update README badges with version and… #13
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 Management | |
| # Required permissions for the workflow token | |
| permissions: | |
| contents: write # For commits and pushes | |
| pull-requests: write # For creating releases | |
| on: | |
| push: | |
| branches: | |
| - main # Or your release branch | |
| jobs: | |
| calculate-version: | |
| name: Calculate Next Version | |
| runs-on: ubuntu-latest | |
| outputs: | |
| new_version: ${{ steps.bump_version.outputs.new_version }} | |
| version_commit_sha: ${{ steps.commit_version.outputs.commit_sha }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Required for commit history analysis if used | |
| - name: Set up Git user | |
| run: | | |
| git config user.name "GitHub Actions Bot" | |
| git config user.email "actions@github.com" | |
| - name: Bump version | |
| id: bump_version | |
| run: | | |
| chmod +x .github/scripts/bump-version.sh | |
| ./.github/scripts/bump-version.sh | |
| # In a real scenario, you might pass VERSION_BUMP_TYPE based on commit analysis | |
| # env: | |
| # VERSION_BUMP_TYPE: 'patch' # or 'minor', 'major' | |
| - name: Commit version bump | |
| id: commit_version | |
| run: | | |
| git add n8n-manager.sh | |
| git commit -m "chore(release): bump version to ${{ steps.bump_version.outputs.new_version }}" | |
| git push | |
| echo "commit_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" | |
| generate-changelog: | |
| name: Generate Changelog | |
| runs-on: ubuntu-latest | |
| needs: calculate-version | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| # Fetch all history for changelog generation | |
| fetch-depth: 0 | |
| # Checkout the branch, not the specific commit, to avoid detached HEAD | |
| ref: ${{ github.ref_name }} | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' # Or your preferred LTS version | |
| - name: Generate changelog | |
| run: | | |
| chmod +x .github/scripts/generate-changelog.sh | |
| ./.github/scripts/generate-changelog.sh | |
| - name: Set up Git user | |
| run: | | |
| git config user.name "GitHub Actions Bot" | |
| git config user.email "actions@github.com" | |
| - name: Commit changelog | |
| run: | | |
| git add CHANGELOG.md | |
| # Check if there are changes to commit to avoid error if changelog is empty or unchanged | |
| if ! git diff --staged --quiet; then | |
| git commit -m "docs(changelog): update CHANGELOG.md for v${{ needs.calculate-version.outputs.new_version }}" | |
| git push origin HEAD:${{ github.ref_name }} # Push to the correct branch | |
| else | |
| echo "No changes to CHANGELOG.md to commit." | |
| fi | |
| update-badges: | |
| name: Update README Badges | |
| runs-on: ubuntu-latest | |
| needs: [calculate-version, generate-changelog] # Depends on new version and changelog commit | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| # Checkout the latest commit on the branch (should include version bump and changelog) | |
| ref: ${{ github.ref_name }} | |
| fetch-depth: 0 # For git history if script needs it | |
| - name: Set up Git user | |
| run: | | |
| git config user.name "GitHub Actions Bot" | |
| git config user.email "actions@github.com" | |
| - name: Update README badges | |
| run: | | |
| chmod +x .github/scripts/update-readme-badges.sh | |
| ./.github/scripts/update-readme-badges.sh | |
| - name: Commit README.md update | |
| run: | | |
| git add README.md | |
| # Check if there are changes to commit | |
| if ! git diff --staged --quiet; then | |
| git commit -m "docs(readme): update badges for v${{ needs.calculate-version.outputs.new_version }}" | |
| git push | |
| else | |
| echo "No changes to README.md badges to commit." | |
| fi | |
| create-release: | |
| name: Create GitHub Release | |
| runs-on: ubuntu-latest | |
| needs: [calculate-version, generate-changelog, update-badges] | |
| # Ensure this job runs only on the main branch and not on tags pushed by this workflow | |
| if: github.ref == 'refs/heads/main' | |
| permissions: | |
| contents: write # To create tags and releases | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| # Checkout the latest commit on the branch (should include version bump, changelog, and badge updates) | |
| ref: ${{ github.ref_name }} | |
| - name: Create GitHub Release | |
| id: create_release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: v${{ needs.calculate-version.outputs.new_version }} | |
| release_name: Release v${{ needs.calculate-version.outputs.new_version }} | |
| body_path: CHANGELOG.md # Assumes changelog is generated and committed | |
| draft: false | |
| prerelease: false |