Repository navigation
272 lines (231 loc) · 8.06 KB
/
Copy pathpublish.yml
File metadata and controls
272 lines (231 loc) · 8.06 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
name: Publish
#
# Read the document (`RELEASES.md`)
# to perform all the steps required
# to run this workflow.
#
on:
workflow_dispatch:
inputs:
skip-luarocks-upload:
description: Skip upload to LuaRocks website
type: boolean
required: true
default: false
skip-github-release:
description: Skip releasing to GitHub Releases
type: boolean
required: true
default: false
jobs:
# Job to extract the library version
# defined in the LUA_HASH_VERSION macro
# on `src/lua-hash.h` file.
#
# Remark: this job stores `none`
# as version output on failure.
get-version-from-library:
name: Get the library version
runs-on: ubuntu-latest
permissions: read-all
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.ref }}
persist-credentials: false
- name: Get version from the library defined at `src/lua-hash.h`
id: version
run: |
pattern="[0-9]+(\\.[0-9]+)+"
version=$(grep -oP "#define\\s+LUA_HASH_VERSION\\s+\"($pattern)\"" src/lua-hash.h | grep -oP "$pattern")
if [[ $version =~ ^$pattern$ ]]; then
echo "version=${version}" >> "${GITHUB_OUTPUT}"
else
echo "version=none" >> "${GITHUB_OUTPUT}"
fi
# Job to get the latest
# versioned rockspec
# tracked by git
# on rockspec folder.
#
# Remark: this job stores `none`
# as rockspec output on failure.
get-latest-rockspec:
name: Get the latest rockspec
runs-on: ubuntu-latest
permissions: read-all
outputs:
rockspec: ${{ steps.rockspec.outputs.rockspec }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.ref }}
persist-credentials: false
- name: Get the latest rockspec sorted by version in the name
id: rockspec
run: |
dev_pattern="lua-hash-(dev|scm|cvs|git|svn|hg)-[0-9]+\\.rockspec"
latest=""
for rockspec in $(git ls-files "rockspecs/lua-hash-*.rockspec" | sort --version-sort); do
rockspec_basename="$(basename "$rockspec")"
if ! [[ $rockspec_basename =~ ^$dev_pattern$ ]]; then
latest="${rockspec}"
fi
done
if test -f "${latest}"; then
echo "rockspec=${latest}" >> "${GITHUB_OUTPUT}"
else
echo "rockspec=none" >> "${GITHUB_OUTPUT}"
fi
# Job to extract the version
# from the tag.
# For instance, for a `v0.0.1`
# tag, this job stores `0.0.1`
# as version output.
#
# Remark: this job stores `none`
# as version output on failure.
get-version-from-tag:
name: Get version from the tag
runs-on: ubuntu-latest
permissions: read-all
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Extract version from the tag
id: version
run: |
if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
pattern="[0-9]+(\\.[0-9]+)+"
version=$(echo "${GITHUB_REF_NAME}" | sed -e "s|v||g" | grep -oP "^$pattern\$")
if [[ $version =~ ^$pattern$ ]]; then
echo "version=${version}" >> "${GITHUB_OUTPUT}"
else
echo "version=none" >> "${GITHUB_OUTPUT}"
fi
else
echo "version=none" >> "${GITHUB_OUTPUT}"
fi
# Job to perform validation
# between different versions:
#
# i) from the `src/lua-hash.h` file;
# ii) from the latest rockspec name;
# iii) from the `source.tag` field
# in the latest rockspec.
match-versions:
name: Match versions from lib, rockspec and tag
runs-on: ubuntu-latest
permissions: read-all
needs:
- get-version-from-library
- get-latest-rockspec
- get-version-from-tag
if: |
${{
needs.get-version-from-library.outputs.version != 'none' &&
needs.get-latest-rockspec.outputs.rockspec != 'none' &&
needs.get-version-from-tag.outputs.version != 'none' &&
needs.get-version-from-library.outputs.version == needs.get-version-from-tag.outputs.version
}}
env:
ROCKSPEC: ${{ needs.get-latest-rockspec.outputs.rockspec }}
LIBVERSION: ${{ needs.get-version-from-library.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.ref }}
persist-credentials: false
- name: Setup Lua and LuaRocks
uses: luau-project/setup-lua@ebdc724769a3976b27abe70d93a730aede440ba9 # v2.0.8
- name: Validate rockspec basename
run: |
rockspec_basename="$(basename "${ROCKSPEC}")"
rockspec_basename_version=$(echo "${rockspec_basename}" | rev | cut -d- -f2 | rev)
if [ "${rockspec_basename_version}" != "${LIBVERSION}" ]; then
echo "version in the basename of the latest rockspec (${rockspec_basename_version}) is not ${LIBVERSION}";
exit 1;
fi
- name: Validate rockspec tag
run: |
rockspec_tag=$(lua -e "dofile(arg[0]); io.write(source.tag);" -- "${ROCKSPEC}")
if [ "${rockspec_tag}" != "${GITHUB_REF_NAME}" ]; then
echo "source.tag (${rockspec_tag}) is not ${GITHUB_REF_NAME}";
exit 1;
fi
publish:
name: Publish to LuaRocks and GitHub Releases
runs-on: ubuntu-latest
needs:
- get-latest-rockspec
- get-version-from-tag
- match-versions
if: |
${{
github.repository == 'luau-project/lua-hash' &&
github.ref_type == 'tag'
}}
permissions:
contents: write
env:
ROCKSPEC: ${{ needs.get-latest-rockspec.outputs.rockspec }}
TAGVERSION: ${{ needs.get-version-from-tag.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.ref }}
- name: Setup Lua and LuaRocks
uses: luau-project/setup-lua@ebdc724769a3976b27abe70d93a730aede440ba9 # v2.0.8
- name: Install system dependencies
run: sudo apt install -y libssl-dev
- name: Install upload dependency (LuaSocket)
run: luarocks install luasocket
- name: Install upload dependency (LuaSec)
run: luarocks install luasec
- name: Install upload dependency (dkjson)
run: luarocks install dkjson
- name: Pack a src rock and set an environment variable to hold its name
run: |
rockspec_basename="$(basename "${ROCKSPEC}")"
srcrock="${rockspec_basename%.*}.src.rock"
luarocks pack "${ROCKSPEC}" || {
echo "Failed to pack a .src.rock from ${ROCKSPEC}"
exit 1
}
echo "SRC_ROCK=${srcrock}" >> "$GITHUB_ENV"
- name: Generate a versioned tarball from the tag
run: |
git archive \
"--format=tar.gz" \
-o "lua-hash-${TAGVERSION}.tar.gz" \
"--prefix=lua-hash-${TAGVERSION}/" \
"${GITHUB_REF}"
- name: Generate a versioned zip from the tag
run: |
git archive \
"--format=zip" \
-o "lua-hash-${TAGVERSION}.zip" \
"--prefix=lua-hash-${TAGVERSION}/" \
"${GITHUB_REF}"
- name: Publish to LuaRocks
if: inputs.skip-luarocks-upload != 'true'
env:
UPLOAD_KEY: ${{ secrets.LUAROCKS_APIKEY }}
run: luarocks upload "${ROCKSPEC}" "--temp-key=${UPLOAD_KEY}"
- name: Publish to GitHub Releases
if: inputs.skip-github-release != 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "${GITHUB_REF_NAME}" \
--generate-notes \
"lua-hash-${TAGVERSION}.tar.gz" \
"lua-hash-${TAGVERSION}.zip" \
"${ROCKSPEC}" \
"${SRC_ROCK}"