-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (118 loc) · 4.33 KB
/
release.yml
File metadata and controls
131 lines (118 loc) · 4.33 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
name: Release
on:
workflow_dispatch:
inputs:
version:
description: "Release version, for example 0.1.0 or v0.1.0"
required: true
push:
branches:
- "main"
paths:
- "rockspec/**"
permissions:
contents: write
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install Lua
uses: leafo/gh-actions-lua@v10
with:
luaVersion: "5.1.5"
- name: Install LuaRocks
uses: leafo/gh-actions-luarocks@v4
with:
luarocksVersion: "3.11.1"
- name: Install upload dependency
run: luarocks install dkjson
- name: Extract release name
id: release_env
shell: bash
env:
HEAD_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
RELEASE_VERSION: ${{ inputs.version }}
run: |
semver_re="^v?([0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?)$"
if [ -n "$RELEASE_VERSION" ]; then
if [[ $RELEASE_VERSION =~ $semver_re ]]; then
version="${BASH_REMATCH[1]}"
else
echo "version input is not correct (expected: X.Y.Z[-prerelease])"
exit 1
fi
else
title="${HEAD_COMMIT_MESSAGE%%$'\n'*}"
if [[ $title =~ ^(.*)\ \(#[0-9]+\)$ ]]; then
title="${BASH_REMATCH[1]}"
fi
title_re="^feat: release v?([0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?)$"
if [[ $title =~ $title_re ]]; then
version="${BASH_REMATCH[1]}"
else
echo "commit format is not correct (expected: feat: release vX.Y.Z[-prerelease])"
exit 1
fi
fi
echo "version=v${version}" >> $GITHUB_OUTPUT
echo "version_without_v=${version}" >> $GITHUB_OUTPUT
if [[ $version == *-* ]]; then
echo "is_prerelease=true" >> $GITHUB_OUTPUT
else
echo "is_prerelease=false" >> $GITHUB_OUTPUT
fi
- name: Verify rockspec exists
id: verify_rockspec
shell: bash
env:
VERSION_WITHOUT_V: ${{ steps.release_env.outputs.version_without_v }}
run: |
rockspec_file="$(python3 - <<'PY'
import os
import re
from pathlib import Path
version = os.environ["VERSION_WITHOUT_V"]
pattern = re.compile(r"^lua-qjson-" + re.escape(version) + r"-(\d+)\.rockspec$")
matches = []
for path in Path("rockspec").glob("lua-qjson-" + version + "-*.rockspec"):
match = pattern.match(path.name)
if match:
matches.append((int(match.group(1)), str(path)))
if not matches:
raise SystemExit("rockspec file not found for version " + version)
print(max(matches)[1])
PY
)"
echo "rockspec_file=${rockspec_file}" >> $GITHUB_OUTPUT
- name: Validate LuaRocks token
shell: bash
env:
LUAROCKS_TOKEN: ${{ secrets.LUAROCKS_TOKEN }}
run: |
if [ -z "$LUAROCKS_TOKEN" ]; then
echo "LUAROCKS_TOKEN secret is not configured"
exit 1
fi
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.release_env.outputs.version }}
name: ${{ steps.release_env.outputs.version }}
draft: false
prerelease: ${{ steps.release_env.outputs.is_prerelease }}
- name: Upload to LuaRocks
env:
LUAROCKS_TOKEN: ${{ secrets.LUAROCKS_TOKEN }}
ROCKSPEC_FILE: ${{ steps.verify_rockspec.outputs.rockspec_file }}
shell: bash
run: |
mkdir -p "$HOME/.luarocks"
chmod 700 "$HOME/.luarocks"
lua -e 'local token = os.getenv("LUAROCKS_TOKEN"); assert(token and token ~= "", "missing LUAROCKS_TOKEN"); local f = assert(io.open(os.getenv("HOME") .. "/.luarocks/upload_config.lua", "w")); f:write(("key = %q\n"):format(token)); f:write("server = \"https://luarocks.org\"\nversion = \"1.0\"\n"); f:close()'
chmod 600 "$HOME/.luarocks/upload_config.lua"
luarocks upload "$ROCKSPEC_FILE"