Repository navigation
198 lines (179 loc) · 7.37 KB
/
Copy pathrelease.yml
File metadata and controls
198 lines (179 loc) · 7.37 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
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: Existing v* tag to publish
required: true
type: string
permissions:
contents: write
concurrency:
group: release-${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
cancel-in-progress: false
env:
CARGO_NET_GIT_FETCH_WITH_CLI: "true"
CARGO_TARGET_DIR: ${{ github.workspace }}/target
NGINX_CORE_VERSION: "1.31.4"
NGINX_CORE_TARBALL_SHA256: "e6f20b644a17a643f059ae6467a1971fe2811587d025e071068753a1f1e3b3c3"
NGINX_SOURCE_DIR: ${{ github.workspace }}/.release/nginx-1.31.4
NGINX_BUILD_DIR: ${{ github.workspace }}/.release/nginx-1.31.4/objs
NGX_RUSTSCRIPT_NGINX: ${{ github.workspace }}/.release/nginx-1.31.4/objs/nginx
NGX_RUSTSCRIPT_TASK_TMP: ${{ github.workspace }}/.release/tmp
TMPDIR: ${{ github.workspace }}/.release/tmp
jobs:
verify:
permissions:
contents: read
uses: ./.github/workflows/ci.yml
with:
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
publish:
needs: verify
name: Build and publish linux-amd64 packages
runs-on: ubuntu-24.04
timeout-minutes: 45
steps:
- name: Resolve release tag
id: release
env:
INPUT_TAG: ${{ inputs.tag }}
REF_TAG: ${{ github.ref_name }}
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
TAG="$INPUT_TAG"
else
TAG="$REF_TAG"
fi
if [[ ! "$TAG" =~ ^v[0-9][0-9A-Za-z.+-]*$ ]]; then
echo "release tag must match v*: $TAG" >&2
exit 1
fi
printf 'tag=%s\n' "$TAG" >> "$GITHUB_OUTPUT"
- name: Check out release tag
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
fetch-depth: 0
persist-credentials: false
ref: ${{ steps.release.outputs.tag }}
- name: Validate tag and package version
env:
RELEASE_TAG: ${{ steps.release.outputs.tag }}
run: |
git show-ref --verify --quiet "refs/tags/$RELEASE_TAG" || {
echo "release tag does not exist: $RELEASE_TAG" >&2
exit 1
}
VERSION="${RELEASE_TAG#v}"
CARGO_VERSION="$(python3 - <<'PY'
import tomllib
with open('Cargo.toml', 'rb') as handle:
print(tomllib.load(handle)['package']['version'])
PY
)"
if [[ "$VERSION" != "$CARGO_VERSION" ]]; then
echo "tag version $VERSION does not match Cargo.toml $CARGO_VERSION" >&2
exit 1
fi
printf 'VERSION=%s\n' "$VERSION" >> "$GITHUB_ENV"
printf 'RELEASE_TAG=%s\n' "$RELEASE_TAG" >> "$GITHUB_ENV"
- name: Install native build dependencies
run: |
sudo apt-get update
sudo apt-get install --yes --no-install-recommends \
build-essential ca-certificates clang curl dpkg-dev file libclang-dev \
libpcre2-dev libssl-dev python3-yaml zlib1g-dev
- name: Install Rust toolchain
run: |
rustup toolchain install stable --profile minimal
rustup default stable
rustc --version
cargo --version
- name: Cache Cargo dependencies
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: |
~/.cargo/git
~/.cargo/registry
key: cargo-release-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('Cargo.lock') }}
restore-keys: |
cargo-release-${{ runner.os }}-${{ runner.arch }}-
cargo-${{ runner.os }}-${{ runner.arch }}-
- name: Configure pinned NGINX
run: |
mkdir -p .release/download "$NGX_RUSTSCRIPT_TASK_TMP"
curl --fail --location --retry 3 \
--output ".release/download/nginx-${NGINX_CORE_VERSION}.tar.gz" \
"https://nginx.org/download/nginx-${NGINX_CORE_VERSION}.tar.gz"
printf '%s %s\n' "$NGINX_CORE_TARBALL_SHA256" ".release/download/nginx-${NGINX_CORE_VERSION}.tar.gz" \
| sha256sum --check --strict
tar -C .release -xzf ".release/download/nginx-${NGINX_CORE_VERSION}.tar.gz"
unset CFLAGS CPPFLAGS BINDGEN_EXTRA_CLANG_ARGS
cd "$NGINX_SOURCE_DIR"
./configure --with-compat --with-http_ssl_module
make -j"$(nproc)"
REPORT="$("$NGX_RUSTSCRIPT_NGINX" -V 2>&1)"
[[ "$REPORT" == *"nginx/$NGINX_CORE_VERSION"* ]]
[[ "$REPORT" == *"--with-compat"* ]]
[[ "$REPORT" == *"--with-http_ssl_module"* ]]
test -f "$NGINX_BUILD_DIR/ngx_auto_config.h"
printf 'CFLAGS=-I%s\n' "$NGINX_BUILD_DIR" >> "$GITHUB_ENV"
printf 'BINDGEN_EXTRA_CLANG_ARGS=-I%s\n' "$NGINX_BUILD_DIR" >> "$GITHUB_ENV"
- name: Build release module
run: cargo build --locked --release --lib
- name: Verify release module
env:
NGX_RUSTSCRIPT_MODULE: ${{ github.workspace }}/target/release/libngx_rustscript.so
run: |
DESCRIPTION="$(file -b "$NGX_RUSTSCRIPT_MODULE")"
[[ "$DESCRIPTION" == *ELF* && "$DESCRIPTION" == *"x86-64"* && "$DESCRIPTION" == *"shared object"* ]]
cargo test --locked --test module_load -- --test-threads=1 --nocapture
- name: Test and build packages
run: |
python3 -m unittest -v tests/test_release_packaging.py
mkdir -p dist
scripts/package_release.sh \
--version "$VERSION" \
--arch amd64 \
--module "$CARGO_TARGET_DIR/release/libngx_rustscript.so" \
--nginx "$NGX_RUSTSCRIPT_NGINX" \
--nginx-source "$NGINX_SOURCE_DIR" \
--output-dir dist
(cd dist && sha256sum --check --strict SHA256SUMS)
test -f "dist/ngx-rustscript-module-${VERSION}-linux-amd64.tgz"
test -f "dist/ngx-rustscript-nginx-${VERSION}-nginx-${NGINX_CORE_VERSION}-linux-amd64.tgz"
test -f "dist/nginx-module-rustscript_${VERSION}_amd64.deb"
- name: Upload workflow artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: ngx-rustscript-${{ env.VERSION }}-linux-amd64
path: |
dist/ngx-rustscript-module-${{ env.VERSION }}-linux-amd64.tgz
dist/ngx-rustscript-nginx-${{ env.VERSION }}-nginx-${{ env.NGINX_CORE_VERSION }}-linux-amd64.tgz
dist/nginx-module-rustscript_${{ env.VERSION }}_amd64.deb
dist/SHA256SUMS
if-no-files-found: error
overwrite: true
- name: Create GitHub release if needed
env:
GH_TOKEN: ${{ github.token }}
run: |
if ! gh release view "$RELEASE_TAG" >/dev/null 2>&1; then
gh release create "$RELEASE_TAG" \
--verify-tag \
--title "$RELEASE_TAG" \
--generate-notes
fi
- name: Upload GitHub release assets
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release upload "$RELEASE_TAG" \
"dist/ngx-rustscript-module-${VERSION}-linux-amd64.tgz" \
"dist/ngx-rustscript-nginx-${VERSION}-nginx-${NGINX_CORE_VERSION}-linux-amd64.tgz" \
"dist/nginx-module-rustscript_${VERSION}_amd64.deb" \
dist/SHA256SUMS \
--clobber