|
| 1 | +# Bump Go Version File Action |
| 2 | + |
| 3 | +This GitHub Action automatically checks for the latest stable Go version and updates your `.go-version` file if needed, then creates a pull request with the changes. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- 🔍 Automatically fetches the latest stable Go version from go.dev |
| 8 | +- 📝 Updates your `.go-version` file when a new version is available |
| 9 | +- 🔄 Creates or updates a pull request with the version bump |
| 10 | +- ⚙️ Fully customizable PR titles, messages, and branch names |
| 11 | +- 🎯 Simple and focused - does one thing well |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +### Basic Usage |
| 16 | + |
| 17 | +```yaml |
| 18 | +name: Bump Go Version |
| 19 | +on: |
| 20 | + schedule: |
| 21 | + - cron: '0 0 * * 1' # Run every Monday at midnight |
| 22 | + workflow_dispatch: # Allow manual triggers |
| 23 | + |
| 24 | +jobs: |
| 25 | + bump-go: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + permissions: |
| 28 | + contents: write |
| 29 | + pull-requests: write |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - uses: chainguard-dev/actions/bump-go-version-file@main |
| 34 | + with: |
| 35 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 36 | +``` |
| 37 | +
|
| 38 | +### Advanced Usage |
| 39 | +
|
| 40 | +```yaml |
| 41 | +name: Bump Go Version |
| 42 | +on: |
| 43 | + schedule: |
| 44 | + - cron: '0 0 * * 1' |
| 45 | + workflow_dispatch: |
| 46 | + |
| 47 | +jobs: |
| 48 | + bump-go: |
| 49 | + runs-on: ubuntu-latest |
| 50 | + permissions: |
| 51 | + contents: write |
| 52 | + pull-requests: write |
| 53 | + steps: |
| 54 | + - uses: actions/checkout@v4 |
| 55 | + |
| 56 | + - uses: chainguard-dev/actions/bump-go-version-file@main |
| 57 | + with: |
| 58 | + go-version-file: '.go-version' |
| 59 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 60 | + branch-for-pr: 'automated/bump-go-version' |
| 61 | + title-for-pr: '🚀 Update Go version' |
| 62 | + description-for-pr: | |
| 63 | + ## Go Version Update |
| 64 | + |
| 65 | + This PR updates the Go version to the latest stable release. |
| 66 | + |
| 67 | + Please review and merge if tests pass. |
| 68 | + commit-message: 'chore(deps): bump Go version' |
| 69 | + labels-for-pr: 'automated pr, dependencies, go' |
| 70 | + base-branch: 'main' |
| 71 | + author: '${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>' |
| 72 | + signoff: true |
| 73 | +``` |
| 74 | +
|
| 75 | +### Dry-run Mode (Testing) |
| 76 | +
|
| 77 | +Use dry-run mode to test the action without creating a PR: |
| 78 | +
|
| 79 | +```yaml |
| 80 | +- uses: chainguard-dev/actions/bump-go-version-file@main |
| 81 | + with: |
| 82 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 83 | + dry-run: 'true' |
| 84 | +``` |
| 85 | +
|
| 86 | +In dry-run mode, the action will: |
| 87 | +- Check for Go version updates |
| 88 | +- Show what changes would be made |
| 89 | +- Display the diff in the workflow summary |
| 90 | +- **Not** create a pull request |
| 91 | +
|
| 92 | +## Inputs |
| 93 | +
|
| 94 | +| Input | Description | Required | Default | |
| 95 | +|-------|-------------|----------|---------| |
| 96 | +| `go-version-file` | Path to the go version file | No | `.go-version` | |
| 97 | +| `token` | GITHUB_TOKEN or a `repo` scoped PAT | Yes | `${{ github.token }}` | |
| 98 | +| `signoff` | Add `Signed-off-by` line to commit message | No | `false` | |
| 99 | +| `author` | Author name and email in format `Name <email>` | No | `${{ github.actor }} <...>` | |
| 100 | +| `committer` | Committer name and email in format `Name <email>` | No | `github-actions[bot] <...>` | |
| 101 | +| `labels-for-pr` | Comma or newline separated list of PR labels | No | `automated pr, dependencies` | |
| 102 | +| `branch-for-pr` | Branch name for the PR | No | `bump-go-version` | |
| 103 | +| `title-for-pr` | PR title | No | `chore: bump Go version` | |
| 104 | +| `description-for-pr` | PR body/description | No | See action.yml | |
| 105 | +| `commit-message` | Commit message | No | `chore: bump Go version` | |
| 106 | +| `base-branch` | Base branch for the PR | No | `main` | |
| 107 | +| `dry-run` | Run in dry-run mode (show changes without creating PR) | No | `false` | |
| 108 | + |
| 109 | +## Outputs |
| 110 | + |
| 111 | +| Output | Description | |
| 112 | +|--------|-------------| |
| 113 | +| `pull_request_number` | The PR number if created | |
| 114 | +| `old-version` | The old Go version (e.g., `1.23.4`) | |
| 115 | +| `new-version` | The new Go version (e.g., `1.24.0`) | |
| 116 | + |
| 117 | +## Example `.go-version` File |
| 118 | + |
| 119 | +Your repository should contain a `.go-version` file with just the Go version: |
| 120 | + |
| 121 | +``` |
| 122 | +1.23.4 |
| 123 | +``` |
| 124 | + |
| 125 | +The action will update this file to the latest stable version when available. |
| 126 | + |
| 127 | +## Permissions |
| 128 | + |
| 129 | +Make sure your workflow has the necessary permissions: |
| 130 | + |
| 131 | +```yaml |
| 132 | +permissions: |
| 133 | + contents: write # To push the branch |
| 134 | + pull-requests: write # To create PRs |
| 135 | +``` |
| 136 | + |
| 137 | +## How It Works |
| 138 | + |
| 139 | +1. The action fetches the latest stable Go version from `https://go.dev/VERSION?m=text` |
| 140 | +2. It reads your `.go-version` file and compares the versions |
| 141 | +3. If the versions match, it exits without making changes |
| 142 | +4. If an update is available: |
| 143 | + - Updates the `.go-version` file |
| 144 | + - Checks if there are any changes using `git diff` |
| 145 | + - Uses `peter-evans/create-pull-request` to create/update a PR |
| 146 | + - Automatically includes the diff in the PR description |
| 147 | + |
| 148 | +## Tips |
| 149 | + |
| 150 | +- Use the `workflow_dispatch` trigger to manually run the action |
| 151 | +- Schedule the workflow to run weekly or monthly to stay up to date |
| 152 | +- Customize the PR labels and description to match your team's conventions |
| 153 | +- The action uses `peter-evans/create-pull-request` which handles branch management automatically |
| 154 | +- If a PR already exists, it will be updated with the new changes |
| 155 | + |
| 156 | +## Example Output |
| 157 | + |
| 158 | +When a new version is found, the action will: |
| 159 | +- Update `.go-version` from `1.23.4` to `1.24.0` |
| 160 | +- Create/update a PR with title like "chore: bump Go version (from 1.23.4 to 1.24.0)" |
| 161 | +- Include the old version, new version, and diff in the PR description |
| 162 | +- Output the PR number for use in subsequent workflow steps |
0 commit comments