forked from Kong/lua-resty-simdjson
-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (120 loc) · 4.7 KB
/
release.yml
File metadata and controls
133 lines (120 loc) · 4.7 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
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:
if: "${{ github.event_name == 'workflow_dispatch' || startsWith(github.event.head_commit.message, 'feat: release ') }}"
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
with:
persist-credentials: false
- name: Install Lua
uses: leafo/gh-actions-lua@35bcb06abec04ec87df82e08caa84d545348536e
with:
luaVersion: "5.1.5"
- name: Install LuaRocks
uses: leafo/gh-actions-luarocks@e65774a6386cb4f24e293dca7fc4ff89165b64c5
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"^api7-lua-resty-simdjson-" + re.escape(version) + r"-(\d+)\.rockspec$")
matches = []
for path in Path("rockspec").glob("api7-lua-resty-simdjson-" + 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@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65
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"
touch "$HOME/.luarocks/upload_config.lua"
chmod 600 "$HOME/.luarocks/upload_config.lua"
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")); assert(f:write(("key = %q\n"):format(token))); assert(f:write("server = \"https://luarocks.org\"\nversion = \"1.0\"\n")); assert(f:close())'
luarocks upload "$ROCKSPEC_FILE"