-
Notifications
You must be signed in to change notification settings - Fork 15
162 lines (127 loc) · 5.88 KB
/
release.yml
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
name: Build Release
on:
push:
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10, v2.1.4rc5
permissions:
contents: write
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4.2.0
with:
fetch-depth: 0
- name: Prepare Environment
id: prepare_env
run: |
# Calculate project information
PROJECT="${GITHUB_REPOSITORY#ruipin/}"
PROJECT_NO_FVTT="${PROJECT#fvtt-}"
echo "PROJECT=${PROJECT}" >> "$GITHUB_ENV"
echo "PROJECT_NO_FVTT=${PROJECT_NO_FVTT}" >> "$GITHUB_ENV"
echo "PROJECT=${PROJECT}" >> "$GITHUB_OUTPUT"
echo "PROJECT_NO_FVTT=${PROJECT_NO_FVTT}" >> "$GITHUB_OUTPUT"
# Calculate version information
GIT_HASH="$(git rev-parse HEAD)"
VERSION="${GITHUB_REF#refs/*/v}"
SPLIT_VERSION_1="${VERSION#*.}"
SPLIT_VERSION_2="${SPLIT_VERSION_1#*.}"
MAJOR_VERSION="${VERSION%%.*}"
MINOR_VERSION="${SPLIT_VERSION_1%%.*}"
SPLIT_VERSION_3="${SPLIT_VERSION_2%%[^0-9]*}"
PATCH_VERSION="${SPLIT_VERSION_3}"
SUFFIX_VERSION="${SPLIT_VERSION_2#${SPLIT_VERSION_3}}"
SUFFIX_VERSION="${SUFFIX_VERSION#.}"
SUFFIX_VERSION="${SUFFIX_VERSION#-}"
IS_PRERELEASE="true"
if [[ "$SUFFIX_VERSION" != *rc* && "$SUFFIX_VERSION" != *dev* ]]; then
git merge-base --is-ancestor HEAD origin/master && IS_PRERELEASE="false"
fi
# Store environment
echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT"
echo "MAJOR_VERSION=${MAJOR_VERSION}" >> "$GITHUB_OUTPUT"
echo "MINOR_VERSION=${MINOR_VERSION}" >> "$GITHUB_OUTPUT"
echo "PATCH_VERSION=${PATCH_VERSION}" >> "$GITHUB_OUTPUT"
echo "SUFFIX_VERSION=${SUFFIX_VERSION}" >> "$GITHUB_OUTPUT"
echo "IS_PRERELEASE=${IS_PRERELEASE}" >> "$GITHUB_OUTPUT"
echo "GIT_HASH=${GIT_HASH}" >> "$GITHUB_OUTPUT"
echo "VERSION=${VERSION}" >> "$GITHUB_ENV"
echo "MAJOR_VERSION=${MAJOR_VERSION}" >> "$GITHUB_ENV"
echo "MINOR_VERSION=${MINOR_VERSION}" >> "$GITHUB_ENV"
echo "PATCH_VERSION=${PATCH_VERSION}" >> "$GITHUB_ENV"
echo "SUFFIX_VERSION=${SUFFIX_VERSION}" >> "$GITHUB_ENV"
echo "IS_PRERELEASE=${IS_PRERELEASE}" >> "$GITHUB_ENV"
echo "GIT_HASH=${GIT_HASH}" >> "$GITHUB_ENV"
echo "Project: '$PROJECT' ; Version: '$VERSION' ; Major: '$MAJOR_VERSION' ; Minor: '$MINOR_VERSION' ; Patch: '$PATCH_VERSION' ; Suffix: '$SUFFIX_VERSION' ; Hash: '$GIT_HASH' ; Pre-release: '$IS_PRERELEASE' ;"
# Sanity check
if ! grep "\"${VERSION}\"" module.json ; then
echo "module.json version does not match the tag"
exit 1
fi
shell: bash
- name: Fetch submodules
id: fetch_submodules
run: |
git config --global url."https://github.com/".insteadOf "git@github.com:"
git submodule sync --recursive
git submodule update --init --recursive --force
shell: bash
- name: Prepare node
uses: actions/setup-node@v2
with:
node-version: '20.4'
- name: Prepare npm
run: npm install
- name: Run tests
run: npm run test
- name: Build
run: |
# Prepare 'dist' directory
mkdir -p "dist"
# Copy static files
cp *.md "LICENSE" dist/
[[ -d "templates" ]] && cp -r templates dist/templates
[[ -d "lang" ]] && cp -r lang dist/lang
# Edit module.json manifest
MANIFEST_EDITS=()
function add_manifest_edit {
MANIFEST_EDITS+=('-e' 's~(["'"'"']'"$1"'["'"'"'][[:space:]]*:).*[^,[:space:]](,?)[[:space:]]*$~\1 '"$2"'\2~')
}
add_manifest_edit 'git_version' '"${{ steps.prepare_env.outputs.GIT_HASH }}"'
add_manifest_edit 'esmodules' '\["lib-wrapper.js"\]'
add_manifest_edit 'styles' '\["lib-wrapper.css"\]'
add_manifest_edit 'manifest' '"https://github.com/ruipin/${{ steps.prepare_env.outputs.PROJECT }}/releases/latest/download/module.json"'
add_manifest_edit 'download' '"https://github.com/ruipin/${{ steps.prepare_env.outputs.PROJECT }}/releases/download/v${{ steps.prepare_env.outputs.VERSION }}/${{ steps.prepare_env.outputs.PROJECT_NO_FVTT }}-v${{ steps.prepare_env.outputs.VERSION }}.zip"'
sed -r \
"${MANIFEST_EDITS[@]}" \
module.json > dist/module.json
# Make sure to use modified version of module.json when building the artifact
cp dist/module.json module.json
# Build artifact
npm run build
# Create 7zip file
cd dist
7z a -tzip "../${{ steps.prepare_env.outputs.PROJECT_NO_FVTT }}-v${{ steps.prepare_env.outputs.VERSION }}.zip" "." -mx0
cd ..
cp dist/module.json "module.json"
- name: Create/Upload Zip
uses: ncipollo/release-action@215101a6e62db34b334af623ab3a43e27baa93d9
with:
artifacts: "./${{ steps.prepare_env.outputs.PROJECT_NO_FVTT }}-v${{ steps.prepare_env.outputs.VERSION }}.zip"
artifactContentType: application/zip
allowUpdates: true
replacesArtifacts: true
prerelease: ${{ steps.prepare_env.outputs.IS_PRERELEASE }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Create/Upload Json
uses: ncipollo/release-action@215101a6e62db34b334af623ab3a43e27baa93d9
with:
artifacts: ./module.json
artifactContentType: application/json
allowUpdates: true
replacesArtifacts: true
prerelease: ${{ steps.prepare_env.outputs.IS_PRERELEASE }}
token: ${{ secrets.GITHUB_TOKEN }}