-
Notifications
You must be signed in to change notification settings - Fork 1
194 lines (177 loc) · 5.86 KB
/
buildpkg.yml
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
name: Build packages
on:
push:
# tags:
# - 'v*.*.*'
env:
GO_VERSION: "1.20"
APP_NAME: "gopssh"
MAIN_GO: "cmd/gopssh/main.go"
DESC: "parallel ssh client"
jobs:
info:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Get the info
id: info
run: |
ver=$(date "+%y%m.%d.%S")
[[ $GITHUB_REF == refs\/tags\/v* ]] && ver=${GITHUB_REF/refs\/tags\/v/}
hash=$(git rev-parse --short HEAD)
echo ver=$ver hash=$hash
echo "ver=$ver" >> $GITHUB_OUTPUT
echo "hash=$hash" >> $GITHUB_OUTPUT
- name: show info
run: |
echo "version: ${{ steps.info.outputs.ver }}" >> $GITHUB_STEP_SUMMARY
echo "hash: ${{ steps.info.outputs.hash }}" >> $GITHUB_STEP_SUMMARY
echo "date: $(date --iso-8601=seconds)" >> $GITHUB_STEP_SUMMARY
outputs:
ver: ${{ steps.info.outputs.ver }}
hash: ${{ steps.info.outputs.hash }}
go-test:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: Test
run: |
go test -v ./...
build-binary:
runs-on: ubuntu-22.04
needs: [info, go-test]
strategy:
matrix:
goos: [darwin, linux]
goarch: [amd64, arm64]
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: Build
run: |
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} CGO_ENABLED=0 go build -v \
-ldflags "-X main.version=${{ needs.info.outputs.ver }} \
-X main.commit=${{ needs.info.outputs.hash }} \
-X main.date=$(date --iso-8601=seconds)" \
-o .bin/${{ env.APP_NAME }} \
${{ env.MAIN_GO }}
- uses: actions/upload-artifact@v4
with:
name: bin-${{ matrix.goos }}-${{ matrix.goarch }}
path: |
.bin/*
# build rpm, deb packages
build-linux-packages:
runs-on: ubuntu-22.04
needs: [info, build-binary]
strategy:
matrix:
goarch: [amd64, arm64]
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: "go.mod"
- uses: actions/download-artifact@v4
with:
name: bin-linux-${{ matrix.goarch }}
path: .bin
- name: Build Linux RPM Packages
run: |
ls -la
case ${{ matrix.goarch }} in
"amd64") arch=x86_64;;
"arm64") arch=aarch64;;
esac
NAME=${{ env.APP_NAME }} \
VERSION=${{ needs.info.outputs.ver }} \
HASH=${{ needs.info.outputs.hash }} \
ARCH=$arch \
RELEASE=1 \
BINPATH=.bin/${{ env.APP_NAME }} \
go run pack/rpmpack/main.go
- name: Build Linux DEB Packages
run: |
VERSION="${{ needs.info.outputs.ver }}" \
ARCH="${{ matrix.goarch }}" \
NAME="${{ env.APP_NAME }}" \
DESC="${{ env.DESC }}" \
BINPATH=".bin/${{ env.APP_NAME }}" \
go run pack/debpack/main.go
- uses: actions/upload-artifact@v4
with:
name: linux-packages-${{ matrix.goarch }}
path: |
./*.rpm
./*.deb
- name: show info
run: |
echo "ls -la" >> $GITHUB_STEP_SUMMARY
ls -la >> $GITHUB_STEP_SUMMARY
create-release:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-22.04
needs: [info, build-linux-packages]
steps:
- uses: actions/checkout@v4
- name: Download All Artifacts
uses: actions/download-artifact@v4
- name: Create assets
run: |
mkdir .dist
for os in darwin linux;do
for arch in amd64 arm64;do
cd bin-${os}-${arch}
chmod 755 ${{ env.APP_NAME }}
tar -cvzf ../.dist/${os}-${arch}.tar.gz ${{ env.APP_NAME }}
cd ..
done
done
for arch in amd64 arm64;do
mv linux-packages-${arch}/* .dist
done
ls -la .dist
ls -la .dist>> $GITHUB_STEP_SUMMARY
- name: Create release.md
run: |
cp releasenote.template.md release.md
sed -i -e "s/__amd64rpm__/$(basename .dist/*x86_64.rpm)/" release.md
sed -i -e "s/__arm64rpm__/$(basename .dist/*aarch64.rpm)/" release.md
sed -i -e "s/__amd64deb__/$(basename .dist/*amd64.deb)/" release.md
sed -i -e "s/__arm64deb__/$(basename .dist/*arm64.deb)/" release.md
- name: Release
uses: softprops/action-gh-release@v2
with:
prerelease: true
body_path: release.md
fail_on_unmatched_files: true
generate_release_notes: true
append_body: true
files: |
.dist/*.rpm
.dist/*.deb
.dist/*.tar.gz
- name: Create homebrew Formula
run: |
cp pack/Formula/template.rb gopssh.rb
sed -i -e "s/__version__/v${{ needs.info.outputs.ver }}/g" gopssh.rb
for os in darwin linux;do
for arch in amd64 arm64;do
sed -i -e "s/__${os}-${arch}_sha256__/$(sha256sum .dist/${os}-${arch}.tar.gz|awk '{print $1}')/" gopssh.rb
done
done
mkdir -p ~/.ssh/
echo "${{ secrets.BREWREPOKEY }}" >~/.ssh/id_ed25519 && chmod 600 ~/.ssh/id_ed25519
git config --global user.email "bot@github.com" && git config --global user.name "Github Actions"
git clone git@github.com:masahide/homebrew-tap.git && cd homebrew-tap
cp ../gopssh.rb Formula/ && git add Formula/gopssh.rb
git commit -am"gopssh v${{ needs.info.outputs.ver }}"
git push origin main