-
Notifications
You must be signed in to change notification settings - Fork 0
189 lines (164 loc) · 4.99 KB
/
release.yml
File metadata and controls
189 lines (164 loc) · 4.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
name: Release
on: [push]
permissions:
contents: write
env:
GO_VERSION: '>=1.24.0'
jobs:
check:
name: Check if the main package exists
outputs:
targets: ${{ steps.list.outputs.targets }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
- name: List "main" packages to be released
id: list
run: |
found=0
echo "targets<<__END__" >> $GITHUB_OUTPUT
go list -f '{{if (eq .Name "main")}}{{.ImportPath}} .{{slice .ImportPath (len .Module.Path)}}{{end}}' ./... | while IFS= read -r line ; do
read -a e <<< "$line"
path="${e[0]}"
dir="${e[1]}"
name=$(basename $path)
if [ -f "$dir/.norelease" ] ; then
echo -e "Skipped $name\t($dir), due to $dir/.norelease found"
else
found=1
echo "$name $dir $path" >> $GITHUB_OUTPUT
echo -e "Added $name\t($dir) to the release"
fi
done
echo "__END__" >> $GITHUB_OUTPUT
if [[ $found == 0 ]] ; then
echo "⛔ No packages found to release"
fi
build:
name: Build releases
needs: check
if: needs.check.outputs.targets != ''
env:
RELEASE_TARGETS: ${{needs.check.outputs.targets}}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- ubuntu-24.04-arm
- macos-latest
- windows-latest
arch:
- amd64
- arm64
exclude:
- os: windows-latest
arch: arm64
- os: ubuntu-latest
arch: arm64
- os: ubuntu-24.04-arm
arch: amd64
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
- name: Setup env
id: setup
shell: bash
run: |
export NAME="${GITHUB_REPOSITORY#${GITHUB_REPOSITORY_OWNER}/}"
if [[ ${GITHUB_REF} =~ ^refs/tags/v[0-9]+\.[0-9]+ ]] ; then
export VERSION=${GITHUB_REF_NAME}
else
export VERSION=SNAPSHOT
fi
echo "VERSION=${VERSION}" >> $GITHUB_ENV
case ${{ matrix.os }} in
ubuntu-*)
export GOOS=linux
export PKGEXT=.tar.gz
;;
macos-*)
export GOOS=darwin
export PKGEXT=.zip
;;
windows-*)
choco install zip
export GOOS=windows
export PKGEXT=.zip
;;
esac
export GOARCH=${{ matrix.arch }}
echo "GOOS=${GOOS}" >> $GITHUB_ENV
echo "GOARCH=${GOARCH}" >> $GITHUB_ENV
echo "CGO_ENABLED=1" >> $GITHUB_ENV
echo "PKGNAME=${NAME}_${VERSION}_${GOOS}_${GOARCH}" >> $GITHUB_ENV
echo "PKGEXT=${PKGEXT}" >> $GITHUB_ENV
- name: Build all "main" packages
shell: bash
run: |
echo "$RELEASE_TARGETS" | while IFS= read -r line ; do
read -a entry <<< "$line"
printf "building %s\t(%s)\n" "${entry[0]}" "${entry[1]}"
( cd "${entry[1]}" && go build )
done
- name: Archive
shell: bash
run: |
mkdir -p _build/${PKGNAME}
echo "$RELEASE_TARGETS" | while IFS= read -r line ; do
read -a entry <<< "$line"
cp "${entry[1]}/${entry[0]}" _build/${PKGNAME}
done
cp -p LICENSE _build/${PKGNAME}
cp -p README.md _build/${PKGNAME}
case "${PKGEXT}" in
".tar.gz")
tar caf _build/${PKGNAME}${PKGEXT} -C _build ${PKGNAME}
;;
".zip")
(cd _build && zip -r9q ${PKGNAME}${PKGEXT} ${PKGNAME})
;;
esac
ls -laFR _build
- name: Artifact upload
uses: actions/upload-artifact@v5
with:
name: ${{ env.GOOS }}_${{ env.GOARCH }}
path: _build/${{ env.PKGNAME }}${{ env.PKGEXT }}
create-release:
name: Create release
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs:
- build
steps:
- uses: actions/download-artifact@v7
with: { name: darwin_amd64 }
- uses: actions/download-artifact@v7
with: { name: darwin_arm64 }
- uses: actions/download-artifact@v7
with: { name: linux_amd64 }
- uses: actions/download-artifact@v7
with: { name: linux_arm64 }
- uses: actions/download-artifact@v7
with: { name: windows_amd64 }
- run: ls -lafR
- name: Release
uses: softprops/action-gh-release@5be0e66d93ac7ed76da52eca8bb058f665c3a5fe # v2.4.2
with:
draft: true
prerelease: ${{ contains(github.ref_name, '-alpha.') || contains(github.ref_name, '-beta.') }}
files: |
*.tar.gz
*.zip
fail_on_unmatched_files: true
generate_release_notes: true
append_body: true
# based on: github.com/koron-go/_skeleton/.github/workflows/release.yml
# $Hash:a9354833cf3f815f347887d0b11c95c61a362262f9715036ff827975$