-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (144 loc) · 4.73 KB
/
tagpr.yaml
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
# .github/workflows/tagpr.yml
name: tagpr
on:
push:
branches: ["main"]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
tagpr:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
outputs:
tag: ${{ steps.tagpr.outputs.tag }}
steps:
- uses: actions/checkout@v3
- id: tagpr
uses: Songmu/tagpr@v1
- name: Adding summary
run: echo '### ${{steps.tagpr.outputs.tag}}' >> $GITHUB_STEP_SUMMARY
if: ${{ steps.tagpr.outputs.tag != '' }}
build-linux-bin:
needs: [tagpr]
if: ${{ needs.tagpr.outputs.tag != '' }}
strategy:
matrix:
GOARCH: ['amd64']
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ needs.tagpr.outputs.tag }}
- uses: actions/setup-go@v2
with:
go-version: "1.20"
- name: build bin
run: |
mkdir -p build
go build -o build/psql-front-linux-$GOARCH -ldflags "-s -w -X github.com/mashiike/psql-front.Version=$GIT_VER" cmd/psql-front/*.go
env:
GIT_VER: ${{ needs.tagpr.outputs.tag }}
GOARCH: ${{ matrix.GOARCH }}
shell: bash
- uses: actions/upload-artifact@v3
with:
name: build
path: build/psql-front-*
build-macos-bin:
needs: [tagpr]
if: ${{ needs.tagpr.outputs.tag != '' }}
strategy:
matrix:
GOARCH: ['amd64']
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ needs.tagpr.outputs.tag }}
- uses: actions/setup-go@v2
with:
go-version: "1.20"
- name: build bin
run: |
mkdir -p build
go build -o build/psql-front-darwin-$GOARCH -ldflags "-s -w -X github.com/mashiike/psql-front.Version=$GIT_VER" cmd/psql-front/*.go
env:
GIT_VER: ${{ needs.tagpr.outputs.tag }}
GOARCH: ${{ matrix.GOARCH }}
shell: bash
- uses: actions/upload-artifact@v3
with:
name: build
path: build/psql-front-*
release-bin:
needs: [tagpr, build-linux-bin, build-macos-bin]
if: ${{ needs.tagpr.outputs.tag != '' }}
runs-on: ubuntu-latest
env:
BIN_NAME: psql-front
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ needs.tagpr.outputs.tag }}
- name: load build
id: load_build
uses: actions/download-artifact@v3
with:
name: build
path: build
- name: archive binaries
run: |
cd ${{steps.load_build.outputs.download-path}}
for file in ./* ; do
mkdir $(echo ${file}|awk -F- '{print "${{ env.BIN_NAME }}_"$(NF-1)"_"$(NF)}') &&
cp ${file} $(echo ${file}|awk -F- '{print "${{ env.BIN_NAME }}_"$(NF-1)"_"$(NF)}')/${{ env.BIN_NAME }} &&
cp ../README.md $(echo ${file}|awk -F- '{print "${{ env.BIN_NAME }}_"$(NF-1)"_"$(NF)}')/ &&
cp ../LICENSE $(echo ${file}|awk -F- '{print "${{ env.BIN_NAME }}_"$(NF-1)"_"$(NF)}')/ &&
tar -zcvf $(echo ${file}|awk -F- '{print "${{ env.BIN_NAME }}_"$(NF-1)"_"$(NF)}').tar.gz $(echo ${file}|awk -F- '{print "${{ env.BIN_NAME }}_"$(NF-1)"_"$(NF)}')
done
shasum -a 256 *.tar.gz > ${{ env.BIN_NAME }}_${{ steps.set-tag.outputs.version }}_checksums.txt
ls -lR ./
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-and-push-image:
needs: [tagpr]
if: ${{ needs.tagpr.outputs.tag != '' }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ needs.tagpr.outputs.tag }}
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v2
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: type=semver,pattern={{raw}},value=${{ needs.tagpr.outputs.tag }}
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: Version=${{ needs.tagpr.outputs.tag }}