build(deps): bump bufbuild/buf-setup-action from 1.28.1 to 1.40.1 #119
Workflow file for this run
This file contains 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 | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
type: string | |
description: Semantic Version (major.minor.patch) | |
pull_request: | |
types: | |
- closed | |
push: | |
tags: | |
- v* | |
env: | |
VERSION: ${{ github.event.inputs.version }} | |
APP_ID: 285308 | |
jobs: | |
prepare: | |
runs-on: ubuntu-latest | |
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version != '' }} | |
steps: | |
- name: Generate app token | |
id: token | |
uses: tibdex/github-app-token@v2 | |
with: | |
app_id: ${{env.APP_ID}} | |
private_key: ${{ secrets.RELEASE_BOT_PRIVATE_KEY }} | |
repository: ${{ github.repository }} | |
permissions: >- | |
{"contents": "write", "pull_requests": "write"} | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ steps.token.outputs.token }} | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: stable | |
- run: | | |
sed -i "s/Version.*=.*\"[0-9]\.[0-9][0-9]*\.[0-9][0-9]*.*\"/Version = \"${{ github.event.inputs.version }}\"/g" internal/version/version.go | |
gofmt -s -w internal/version/version.go | |
- name: File PR | |
uses: peter-evans/create-pull-request@v5 | |
with: | |
add-paths: . | |
commit-message: "update version to v${{env.VERSION}}" | |
branch: release/v${{env.VERSION}} | |
delete-branch: true | |
title: "Release v${{env.VERSION}}" | |
body: | | |
Prepare release for ${{env.VERSION}}. | |
token: ${{ steps.token.outputs.token }} | |
tag: | |
runs-on: ubuntu-latest | |
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release') }} | |
steps: | |
- name: Generate app token | |
id: token | |
uses: tibdex/github-app-token@v2 | |
with: | |
app_id: ${{env.APP_ID}} | |
private_key: ${{ secrets.RELEASE_BOT_PRIVATE_KEY }} | |
repository: ${{ github.repository }} | |
permissions: >- | |
{"contents": "write"} | |
- name: Set VERSION from branch | |
run: | | |
VERSION=${{github.head_ref}} | |
echo "VERSION=${VERSION##*/}" >> $GITHUB_ENV | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ steps.token.outputs.token }} | |
fetch-depth: 0 | |
- name: Tag | |
run: | | |
git config --global user.password ${{ steps.token.outputs.token }} | |
git tag -d ${{env.VERSION}} 2> /dev/null || echo 'local ref does not exist' | |
git push origin :${{env.VERSION}} 2> /dev/null || echo 'remote ref does not exist' | |
git tag ${{env.VERSION}} | |
git push origin ${{env.VERSION}} | |
build: | |
runs-on: ubuntu-latest | |
if: ${{ github.event_name == 'push' && startsWith(github.ref_name, 'v') && github.ref_type == 'tag'}} | |
strategy: | |
matrix: | |
goos: | |
- linux | |
goarch: | |
- amd64 | |
- arm64 | |
steps: | |
- name: Generate app token | |
id: token | |
uses: tibdex/github-app-token@v2 | |
with: | |
app_id: ${{env.APP_ID}} | |
private_key: ${{ secrets.RELEASE_BOT_PRIVATE_KEY }} | |
repository: ${{ github.repository }} | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: stable | |
- id: go-cache-paths | |
run: |- | |
echo "go-build=$(go env GOCACHE)" >> $GITHUB_OUTPUT | |
echo "go-mod=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT | |
- uses: actions/cache@v3 | |
with: | |
key: ${{ runner.os }}-${{ matrix.goos }}-${{ matrix.goarch }}-go-build-${{ hashFiles('**/go.sum') }} | |
path: ${{ steps.go-cache-paths.outputs.go-build }} | |
- uses: actions/cache@v3 | |
with: | |
key: ${{ runner.os }}-${{ matrix.goos }}-${{ matrix.goarch }}-go-mod-${{ hashFiles('**/go.sum') }} | |
path: ${{ steps.go-cache-paths.outputs.go-mod }} | |
- run: git config --global url."https://bearer:${{ steps.token.outputs.token }}@github.com".insteadOf "https://github.com" | |
- run: mkdir bin && go build -ldflags="-w -s" -o bin/protoc-gen-gorm-${{ matrix.goos }}-${{ matrix.goarch }} ./ | |
env: | |
CGO_ENABLED: 0 | |
GOOS: ${{ matrix.goos }} | |
GOARCH: ${{ matrix.goarch }} | |
- name: Compress | |
uses: crazy-max/ghaction-upx@v3 | |
with: | |
version: latest | |
files: bin/* | |
args: -9q | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: protoc-gen-gorm-${{ matrix.goos }}-${{ matrix.goarch }} | |
path: bin/protoc-gen-gorm-${{ matrix.goos }}-${{ matrix.goarch }} | |
perform: | |
needs: | |
- build | |
runs-on: ubuntu-latest | |
if: ${{ github.event_name == 'push' && startsWith(github.ref_name, 'v') && github.ref_type == 'tag'}} | |
steps: | |
- name: Generate app token | |
id: token | |
uses: tibdex/github-app-token@v2 | |
with: | |
app_id: ${{env.APP_ID}} | |
private_key: ${{ secrets.RELEASE_BOT_PRIVATE_KEY }} | |
repository: ${{ github.repository }} | |
permissions: >- | |
{"contents": "write", "pull_requests": "write"} | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
fetch-depth: 0 | |
- name: Set VERSION from tag | |
run: | | |
echo "VERSION=${{github.ref_name}}" >> $GITHUB_ENV | |
- uses: actions/download-artifact@v4 | |
with: | |
path: ${{github.workspace}}/bin | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: stable | |
- name: Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
token: ${{ steps.token.outputs.token }} | |
files: | | |
${{github.workspace}}/bin/** | |
- name: Trigger action release | |
uses: peter-evans/repository-dispatch@v2 | |
with: | |
repository: complex64/protoc-gen-gorm | |
token: ${{ steps.token.outputs.token }} | |
event-type: release | |
client-payload: '{"version":"${{env.VERSION}}"}' |