-
Notifications
You must be signed in to change notification settings - Fork 0
160 lines (152 loc) · 4.6 KB
/
build.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
name: Build and Test and Publish
on:
push:
paths-ignore:
- README.md
- LICENSE
workflow_dispatch:
inputs:
skip-build-image:
description: Skip building the builder image
type: boolean
default: false
release:
types: [published]
pull_request:
types: [opened, synchronize, reopened]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
GITHUB_TOKEN: "_DUMMY_"
NODE_AUTH_TOKEN: "_DUMMY_"
jobs:
build-image:
name: Preapre builder image
runs-on: ubuntu-latest
if: ${{ !github.event.inputs.skip-build-image }}
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/metadata-action@v5
id: meta
with:
images: ghcr.io/${{ github.repository }}/builder
tags: |
type=raw,value=latest
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
labels: |
org.opencontainers.image.title=Builder
org.opencontainers.image.description=Builder image for libxmlwasm
org.opencontainers.image.source=${{ github.repository }}
- name: Prepare container
uses: docker/build-push-action@v5
with:
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true
pull: true
build:
name: Build and test
runs-on: ubuntu-latest
needs: build-image
steps:
- uses: actions/checkout@v4
- name: Cache Primes
uses: actions/cache@v4
with:
path: |
cache
key: buildcache
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build
run: |
mkdir -p prefix dist wasm-build cache
chmod o+w prefix dist wasm-build cache
docker compose up ci --no-build
- name: Install dependencies
run: corepack pnpm install --frozen-lockfile
- name: Run tests
run: corepack pnpm test
- name: Create package tarball
run: corepack pnpm pack
- name: Upload package tarball
uses: actions/upload-artifact@v4
with:
name: libxml.wasm.tgz
path: libxml.wasm-*.tgz
publish:
name: Publish packages
runs-on: ubuntu-latest
needs: build
if: ${{ github.event_name != 'pull_request' && !startsWith(github.ref_name, 'dependabot/') }}
permissions:
contents: read
packages: write
id-token: write
env:
NPM_CONFIG_PROVENANCE: true
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
- name: Download package tarball
uses: actions/download-artifact@v4
with:
name: libxml.wasm.tgz
- name: Unpack package tarball
run: |
tar axf libxml.wasm-*.tgz
mv package/* .
rm -fr package
- name: Prepare package
id: package
env:
REF_NAME: ${{ github.ref_name }}
run: |
if [ ${{ github.event_name }} = release ]; then
echo "This is stable release"
echo "tag=latest" >> $GITHUB_OUTPUT
else
echo "This is the develop release"
./scripts/jqout.sh '.version+="-'${REF_NAME//\//-}'-${{ github.sha }}"' package.json
echo "tag=experimental" >> $GITHUB_OUTPUT
fi
echo "name=$(jq .name package.json)" >> $GITHUB_OUTPUT
echo "version=$(jq .version package.json)" >> $GITHUB_OUTPUT
- name: Publish package to NPM
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
corepack pnpm publish --access public --tag ${{ steps.package.outputs.tag }} --no-git-checks
- name: Publish package to GitHub Package Registry
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
./scripts/jqout.sh '.name="@${{ github.repository_owner }}/wasm"' package.json
corepack pnpm publish --access public --tag ${{ steps.package.outputs.tag }} --no-git-checks