forked from foundryvtt/dnd5e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
96 lines (83 loc) · 3.23 KB
/
.gitlab-ci.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
# Cache modules in between jobs
# https://docs.gitlab.com/ee/ci/caching/#cache-nodejs-dependencies
cache:
key: $CI_COMMIT_REF_SLUG
paths:
- .npm/
stages:
- build
- deploy
- upload
workflow:
# Run this workflow when a tag is pushed
rules:
- if: $CI_COMMIT_TAG
variables:
ZIP_FILE_NAME: "dnd5e-$CI_COMMIT_TAG.zip"
RELEASE_DOWNLOAD: "https://gitlab.com/$CI_PROJECT_PATH/-/releases/$CI_COMMIT_TAG/downloads/dnd5e-$CI_COMMIT_TAG.zip"
build:
image: node:latest
stage: build
script:
# Extract version from system.json
- PACKAGE_VERSION=$(node -p "require('./system.json').version")
- PACKAGE_DOWNLOAD=$(node -p "require('./system.json').download")
# Validate that the tag being released matches the package version.
- |
if [[ ! $CI_COMMIT_TAG == release-$PACKAGE_VERSION ]]; then
echo "The system.json version does not match tag name."
echo "system.json: $PACKAGE_VERSION"
echo "tag name: $CI_COMMIT_TAG"
echo "Please fix this and push the tag again."
exit 1
fi
# Validate that the package download url matches the release asset that will be created.
- |
if [[ ! $RELEASE_DOWNLOAD == $PACKAGE_DOWNLOAD ]]; then
echo "The system.json download url does not match the created release asset url."
echo "system.json: $PACKAGE_DOWNLOAD"
echo "release asset url: $RELEASE_DOWNLOAD"
echo "Please fix this and push the tag again."
exit 1
fi
# Use cached npm
- npm ci --cache .npm --prefer-offline
# Run build script
- npm run build
# install the zip package
- apt-get update
- apt-get install zip
# zip whitelist of files to distribute
- zip $ZIP_FILE_NAME -r icons lang module json packs/*.db templates tokens ui dnd5e.css dnd5e.js LICENSE.txt OGL.txt README.md system.json template.json
artifacts:
# include the system json and created zip file as artifacts of the job
paths:
- $ZIP_FILE_NAME
- system.json
expire_in: never
# 3. Attach build artifacts as release assets
# https://docs.gitlab.com/ee/ci/yaml/index.html#complete-example-for-release
release:
stage: deploy
image: registry.gitlab.com/gitlab-org/release-cli:latest
script:
- echo 'running release_job'
release:
tag_name: '$CI_COMMIT_TAG'
ref: '$CI_COMMIT_TAG'
description: '**Installation:** To manually install this release, please use the following manifest URL: https://gitlab.com/$CI_PROJECT_PATH/-/releases/$CI_COMMIT_TAG/downloads/system.json'
assets:
links:
# links the release to the system manifest from this CI workflow
- name: 'system.json'
url: https://gitlab.com/$CI_PROJECT_PATH/-/jobs/artifacts/$CI_COMMIT_TAG/raw/system.json?job=build
filepath: '/system.json'
# links the release to the zip file from this CI workflow
- name: '$ZIP_FILE_NAME'
url: https://gitlab.com/$CI_PROJECT_PATH/-/jobs/artifacts/$CI_COMMIT_TAG/raw/$ZIP_FILE_NAME?job=build
filepath: '/$ZIP_FILE_NAME'
upload:
stage: upload
image: curlimages/curl:latest
script: |
curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file system.json "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/dnd5e/latest/system.json"