|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + repository_dispatch: |
| 5 | + types: [openapi-updated] # fired by the server repo on an OpenAPI change |
| 6 | + schedule: |
| 7 | + - cron: '0 6 * * *' # daily fallback, also covers an unwired dispatch |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + version_bump: |
| 11 | + description: 'patch | minor | major' |
| 12 | + required: false |
| 13 | + default: 'patch' |
| 14 | + |
| 15 | +# Go has no package registry and no OIDC publish: a release is just a git tag that |
| 16 | +# pkg.go.dev indexes through the module proxy. The only token needed is the default |
| 17 | +# GITHUB_TOKEN for the commit and tag. There are no publish secrets. |
| 18 | +permissions: |
| 19 | + contents: write |
| 20 | + |
| 21 | +jobs: |
| 22 | + release: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v7 |
| 26 | + with: |
| 27 | + fetch-depth: 0 # need all tags to compute the next version |
| 28 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 29 | + - uses: actions/setup-go@v6 |
| 30 | + with: |
| 31 | + go-version: stable |
| 32 | + |
| 33 | + - name: Regenerate from live spec |
| 34 | + run: go run ./tools/roxygen generate |
| 35 | + |
| 36 | + - name: Detect drift |
| 37 | + id: diff |
| 38 | + run: | |
| 39 | + if git diff --quiet -- specs/openapi.json roxyapi.gen.go roxy.gen.go README.md AGENTS.md docs/llms-full.txt; then |
| 40 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 41 | + else |
| 42 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 43 | + fi |
| 44 | +
|
| 45 | + - name: Vet, build, test |
| 46 | + if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch' |
| 47 | + run: | |
| 48 | + go vet ./... |
| 49 | + go build ./... |
| 50 | + go test ./... |
| 51 | + env: |
| 52 | + ROXY_API_KEY: ${{ secrets.ROXY_API_KEY }} |
| 53 | + |
| 54 | + - name: Compute next version |
| 55 | + id: bump |
| 56 | + if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch' |
| 57 | + run: | |
| 58 | + git fetch --tags --force |
| 59 | + LATEST=$(git tag --list 'v*' --sort=-v:refname | head -1) |
| 60 | + LATEST=${LATEST:-v0.0.0} |
| 61 | + IFS=. read -r MA MI PA <<<"${LATEST#v}" |
| 62 | + case "${{ github.event.inputs.version_bump || 'patch' }}" in |
| 63 | + major) MA=$((MA+1)); MI=0; PA=0 ;; |
| 64 | + minor) MI=$((MI+1)); PA=0 ;; |
| 65 | + *) PA=$((PA+1)) ;; |
| 66 | + esac |
| 67 | + VER="$MA.$MI.$PA" |
| 68 | + sed -i "s/const Version = \".*\"/const Version = \"$VER\"/" version.go |
| 69 | + echo "version=$VER" >> "$GITHUB_OUTPUT" |
| 70 | + echo "Next version: v$VER" |
| 71 | +
|
| 72 | + - name: Commit, tag, push |
| 73 | + if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch' |
| 74 | + run: | |
| 75 | + git config user.name "github-actions[bot]" |
| 76 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 77 | + V=${{ steps.bump.outputs.version }} |
| 78 | + git add specs/openapi.json roxyapi.gen.go roxy.gen.go version.go README.md AGENTS.md docs/llms-full.txt |
| 79 | + git commit -m "release: v$V" |
| 80 | + git tag "v$V" |
| 81 | + git push --follow-tags |
| 82 | +
|
| 83 | + - name: Prompt pkg.go.dev to index the new version |
| 84 | + # The documented way to get a module indexed: ask the proxy for it via the go |
| 85 | + # tool (handles module-path case encoding; no manual curl bang-encoding). |
| 86 | + if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch' |
| 87 | + env: |
| 88 | + GOPROXY: proxy.golang.org |
| 89 | + run: go list -m "github.com/RoxyAPI/sdk-go@v${{ steps.bump.outputs.version }}" || true |
| 90 | + |
| 91 | + - name: Create GitHub release |
| 92 | + if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch' |
| 93 | + uses: softprops/action-gh-release@v3 |
| 94 | + with: |
| 95 | + tag_name: v${{ steps.bump.outputs.version }} |
| 96 | + generate_release_notes: true |
| 97 | + make_latest: 'true' |
0 commit comments