This repository was archived by the owner on Feb 24, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
195 lines (172 loc) · 5.99 KB
/
release.yml
File metadata and controls
195 lines (172 loc) · 5.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
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}}"}'