forked from RealDeuce/torch
-
Notifications
You must be signed in to change notification settings - Fork 21
102 lines (88 loc) · 3.81 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
name: Release Creation
on:
push:
tags:
- 'v*.*.*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Set up our some variables for future use
# Adapted from https://github.community/t/how-to-get-just-the-tag-name/16241/7
# Tag name: ${{ steps.get_vars.outputs.TAG_NAME }}
# Zip name: ${{ steps.get_vars.outputs.ZIP_NAME }}
# Expected Release Download URL: ${{ steps.get_vars.outputs.RELEASE_DOWNLOAD_URL }}
# Expected Release module.json URL: ${{ steps.get_vars.outputs.RELEASE_INSTALL_URL }}
# Stringified module.json contents: ${{ steps.get_vars.outputs.MODULE_JSON }}
- name: Set up variables
id: get_vars
run: |
TAG=${GITHUB_REF/refs\/tags\//}
echo "TAG_NAME=$TAG" >> $GITHUB_OUTPUT
echo "ZIP_NAME=torch-$TAG.zip" >> $GITHUB_OUTPUT
echo "RELEASE_DOWNLOAD_URL=https://github.com/${{github.repository}}/releases/download/$TAG/torch-$TAG.zip" >> $GITHUB_OUTPUT
echo "RELEASE_INSTALL_URL=https://github.com/${{github.repository}}/releases/download/$TAG/module.json" >> $GITHUB_OUTPUT
JSON=$(cat ./module.json)
echo ::set-output name=MODULE_JSON::${JSON//'%'/'%25'}
# Run some tests to make sure our `module.json` is correct
# Exit before setting up node if not
- name: Verify correct naming
env:
TAG_NAME: ${{ steps.get_vars.outputs.TAG_NAME }}
RELEASE_DOWNLOAD: ${{steps.get_vars.outputs.RELEASE_DOWNLOAD_URL}}
# Extract version and download url from module.json
# https://docs.github.com/en/actions/learn-github-actions/expressions#fromjson
PACKAGE_VERSION: ${{fromJSON(steps.get_vars.outputs.MODULE_JSON).version}}
PACKAGE_DOWNLOAD: ${{fromJSON(steps.get_vars.outputs.MODULE_JSON).download}}
run: |
# Validate that the tag being released matches the package version.
if [[ ! $TAG_NAME == v$PACKAGE_VERSION ]]; then
echo "The module.json version does not match tag name."
echo "module.json: v$PACKAGE_VERSION"
echo "tag name: $TAG_NAME"
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 module.json download url does not match the created release asset url."
echo "module.json: $PACKAGE_DOWNLOAD"
echo "release asset url: $RELEASE_DOWNLOAD"
echo "Please fix this and push the tag again."
exit 1
fi
# Set up Node
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: '18.x'
# Set up pnpm
- name: Install Dependencies
uses: pnpm/action-setup@v3
with:
version: 8
run_install: true
# Run our `build` script
- name: Build All
run: |
pnpm install
pnpm build
# Create a zip file with all files required by the module to add to the release
- name: Zip It
run: |
cd dist
zip ${{steps.get_vars.outputs.ZIP_NAME}} -r *.js lang torch.css module.json sources.json README.md
# Create a release for this specific version
- name: Update Release with Files
id: create_version_release
uses: ncipollo/release-action@v1
with:
allowUpdates: true # Set this to false if you want to prevent updating existing releases
name: ${{steps.get_vars.outputs.TAG_NAME}}
draft: false
prerelease: false
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: 'dist/module.json, dist/${{steps.get_vars.outputs.ZIP_NAME}}'
tag: ${{steps.get_vars.outputs.TAG_NAME}}
body: 'Please copy/paste the current release data from CHANGELOG.md into this field'