-
Notifications
You must be signed in to change notification settings - Fork 10
114 lines (100 loc) · 3.74 KB
/
build-wasm.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
name: Publish WASM
on:
push:
branches:
- master
- ci/*
release:
types: [published]
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: '1'
jobs:
publish_wasm_demo:
name: Publish WebAssembly Demo
runs-on: ubuntu-20.04
# only runs for push, so not for releases.
if: ${{ github.event_name == 'push' }}
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/setup-rust-wasm
- name: Yarn install
working-directory: crates/wasm/js-demo
run: yarn install
- name: >
Build WASM pkg
(${{ github.ref == 'refs/heads/master' && '--release' || '--dev' }})
working-directory: crates/wasm
run: |
./scripts/npm-pkg-config.sh \
${{ github.ref != 'refs/heads/master' && '--dev' || '' }} \
--targets browser \
--set-name @citeproc-rs/wasm \
--dest ./pkg \
--features console,dot
- run: yarn build
working-directory: crates/wasm/js-demo
- name: Deploy
if: ${{ github.ref == 'refs/heads/master' }}
uses: peaceiris/actions-gh-pages@v2
env:
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PUBLISH_DIR: ./crates/wasm/js-demo/build
EXTERNAL_REPOSITORY: cormacrelf/citeproc-wasm-demo
PUBLISH_BRANCH: gh-pages
publish_npm:
name: "Publish to NPM"
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Get version info
id: version
run: |
function set-output() {
local name="$1"
local value="$2"
echo "setting output $name -> $value"
echo "::set-output name=$name::$value"
}
IS_TAGGED_RELEASE=${{ github.event_name == 'release' && 'true' || 'false' }}
DRY_RUN=${{ github.event_name == 'push' && github.ref != 'refs/heads/master' && 'true' || 'false' }}
SHORT_SHA=$(git rev-parse --short "$GITHUB_SHA")
set-output short_sha "${SHORT_SHA}"
set-output npm_dry_run "$DRY_RUN"
if $IS_TAGGED_RELEASE; then
TAG=${GITHUB_REF#refs/tags/wasm-}
IFS='-' read -ra _ POST_HYPHEN <<< "$TAG"
if [ -n "$POST_HYPHEN" ]; then
# i.e. there was a -alpha.1 appended, use the `next` dist tag
set-output npm_dist_tag next
else
set-output npm_dist_tag latest
fi
set-output npm_version "$TAG"
else
set-output npm_version "0.0.0-canary-${SHORT_SHA}"
set-output npm_dist_tag canary
fi
- name: >
Will execute: ${{ steps.version.outputs.npm_dry_run == 'true' && '[Dry run]' || ''}}
Publish @citeproc-rs/wasm ${{ steps.version.outputs.npm_version }} to NPM,
dist tag ${{ steps.version.outputs.npm_dist_tag }}
run: echo
- uses: ./.github/actions/setup-rust-wasm
- name: Build for all targets
working-directory: crates/wasm
run: |
./scripts/npm-pkg-config.sh --features console
- name: Configure package for publishing to NPM
working-directory: crates/wasm
run: |
echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_PUBLISH_TOKEN}}" > .npmrc
./scripts/npm-pkg-config.sh --package-only --set-version ${{steps.version.outputs.npm_version }}
- name: Publish @citeproc-rs/wasm to NPM
working-directory: crates/wasm
run: >
npm publish ./dist --access public
--tag ${{ steps.version.outputs.npm_dist_tag }}
${{ steps.version.outputs.npm_dry_run == 'true' && '--dry-run' || '' }}