-
Notifications
You must be signed in to change notification settings - Fork 0
128 lines (109 loc) · 3.9 KB
/
Copy pathrelease.yml
File metadata and controls
128 lines (109 loc) · 3.9 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
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: Existing git tag to release, for example v0.1.0
required: true
type: string
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
env:
RELEASE_MANIFEST_NAME: system.json
RELEASE_ZIP_NAME: yakov-dryh.zip
RELEASE_MANIFEST_URL: https://github.com/iosipov27/yakov-dryh/releases/latest/download/system.json
RELEASE_DOWNLOAD_URL: https://github.com/iosipov27/yakov-dryh/releases/latest/download/yakov-dryh.zip
steps:
- name: Check out source
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Resolve release tag
id: release
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="${{ github.event.inputs.tag }}"
git checkout "$TAG"
else
TAG="${GITHUB_REF_NAME}"
fi
case "$TAG" in
v*)
;;
*)
echo "Expected a tag starting with v, got: $TAG" >&2
exit 1
;;
esac
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "version=${TAG#v}" >> "$GITHUB_OUTPUT"
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Install dependencies
run: npm ci
- name: Build runtime
run: npm run build
- name: Verify tag matches manifest version
env:
EXPECTED_VERSION: ${{ steps.release.outputs.version }}
run: |
node --input-type=module - <<'EOF'
import fs from "node:fs";
const manifest = JSON.parse(fs.readFileSync("system.json", "utf8"));
if (manifest.version !== process.env.EXPECTED_VERSION) {
throw new Error(`system.json version ${manifest.version} does not match tag version ${process.env.EXPECTED_VERSION}`);
}
EOF
- name: Package release assets
env:
MANIFEST_PATH: ${{ runner.temp }}/release/system.json
MANIFEST_URL: ${{ env.RELEASE_MANIFEST_URL }}
DOWNLOAD_URL: ${{ env.RELEASE_DOWNLOAD_URL }}
RELEASE_MANIFEST_PATH: ${{ runner.temp }}/system.json
RELEASE_ZIP_PATH: ${{ runner.temp }}/yakov-dryh.zip
run: |
PACKAGE_DIR="${RUNNER_TEMP}/release"
mkdir -p "$PACKAGE_DIR"
for path in assets lang packs scripts styles templates system.json README.md; do
if [ -e "$path" ]; then
cp -R "$path" "$PACKAGE_DIR/"
fi
done
node --input-type=module - <<'EOF'
import fs from "node:fs";
const manifest = JSON.parse(fs.readFileSync(process.env.MANIFEST_PATH, "utf8"));
manifest.manifest = process.env.MANIFEST_URL;
manifest.download = process.env.DOWNLOAD_URL;
fs.writeFileSync(process.env.MANIFEST_PATH, `${JSON.stringify(manifest, null, 2)}\n`);
EOF
cp "$PACKAGE_DIR/system.json" "$RELEASE_MANIFEST_PATH"
(
cd "$PACKAGE_DIR"
zip -r "$RELEASE_ZIP_PATH" .
)
- name: Verify package structure
env:
RELEASE_ZIP_PATH: ${{ runner.temp }}/yakov-dryh.zip
run: |
unzip -l "$RELEASE_ZIP_PATH"
unzip -l "$RELEASE_ZIP_PATH" system.json >/dev/null
unzip -l "$RELEASE_ZIP_PATH" scripts/main.js >/dev/null
unzip -l "$RELEASE_ZIP_PATH" styles/yakov-dryh.css >/dev/null
- name: Publish GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.release.outputs.tag }}
generate_release_notes: true
overwrite_files: true
files: |
${{ runner.temp }}/${{ env.RELEASE_MANIFEST_NAME }}
${{ runner.temp }}/${{ env.RELEASE_ZIP_NAME }}