1- name : Build and Test
1+ name : Build and Test and Publish
22
33on :
44 push :
55 paths-ignore :
6- - ' README.md'
6+ - README.md
7+ - LICENSE
8+
9+
710 workflow_dispatch :
811 inputs :
912 skip-build-image :
1013 description : Skip building the builder image
1114 type : boolean
1215 default : false
1316
17+ release :
18+ types : [published]
19+
20+ pull_request :
21+ types : [opened, synchronize, reopened]
22+
1423concurrency :
1524 group : ${{ github.workflow }}-${{ github.ref }}
1625 cancel-in-progress : true
1726
27+ env :
28+ GITHUB_TOKEN : " _DUMMY_"
29+ NODE_AUTH_TOKEN : " _DUMMY_"
30+
1831jobs :
1932 build-image :
2033 name : Preapre builder image
3043 - uses : docker/login-action@v3
3144 with :
3245 registry : ghcr.io
33- username : ${{ github.actor }}
46+ username : ${{ github.repository_owner }}
3447 password : ${{ secrets.GITHUB_TOKEN }}
3548 - uses : docker/metadata-action@v5
3649 id : meta
4053 type=raw,value=latest
4154 type=ref,event=branch
4255 type=ref,event=pr
56+ type=ref,event=tag
4357 type=semver,pattern={{version}}
4458 type=semver,pattern={{major}}.{{minor}}
59+ type=semver,pattern={{major}}
4560 type=sha
61+ labels : |
62+ org.opencontainers.image.title=Builder
63+ org.opencontainers.image.description=Builder image for libxmlwasm
64+ org.opencontainers.image.source=${{ github.repository }}
4665 - name : Prepare container
4766 uses : docker/build-push-action@v5
4867 with :
@@ -58,24 +77,79 @@ jobs:
5877 needs : build-image
5978 steps :
6079 - uses : actions/checkout@v4
80+ - name : Cache Primes
81+ uses : actions/cache@v4
82+ with :
83+ path : |
84+ cache
85+ key : buildcache
6186 - uses : actions/setup-node@v4
6287 with :
6388 node-version-file : " .nvmrc"
89+ - uses : docker/login-action@v3
90+ with :
91+ registry : ghcr.io
92+ username : ${{ github.repository_owner }}
93+ password : ${{ secrets.GITHUB_TOKEN }}
6494 - name : Build
6595 run : |
6696 mkdir -p prefix dist wasm-build cache
6797 chmod o+w prefix dist wasm-build cache
68- docker compose up ci
69- - name : Check files
70- run : ls . */
98+ docker compose up ci --no-build
7199 - name : Install dependencies
72- run : corepack yarn install --immutable
100+ run : corepack pnpm install --frozen-lockfile
73101 - name : Run tests
74- run : corepack yarn test
102+ run : corepack pnpm test
75103 - name : Create package tarball
76- run : corepack yarn pack -o libxmlwasm.tgz
104+ run : corepack pnpm pack
77105 - name : Upload package tarball
78106 uses : actions/upload-artifact@v4
79107 with :
80- name : libxmlwasm.tgz
81- path : libxmlwasm.tgz
108+ name : libxml.wasm.tgz
109+ path : libxml.wasm-*.tgz
110+ publish :
111+ name : Publish packages
112+ runs-on : ubuntu-latest
113+ needs : build
114+ if : ${{ github.event_name != 'pull_request' && !startsWith(github.ref_name, 'dependabot/') }}
115+ permissions :
116+ contents : read
117+ packages : write
118+ steps :
119+ - uses : actions/checkout@v4
120+ - uses : actions/setup-node@v4
121+ with :
122+ node-version-file : " .nvmrc"
123+ - name : Download package tarball
124+ uses : actions/download-artifact@v4
125+ with :
126+ name : libxml.wasm.tgz
127+ - name : Unpack package tarball
128+ run : |
129+ tar axf libxml.wasm-*.tgz
130+ mv package/* .
131+ rm -fr package
132+ - name : Prepare package
133+ id : package
134+ run : |
135+ if [ ${{ github.ref_name }} = 'master' || ${{ github.ref_name }} = 'main' ]; then
136+ echo "This is the main branch"
137+ echo "tag=latest" >> $GITHUB_OUTPUT
138+ else
139+ echo "This is the develop branch"
140+ ./scripts/jqout.sh '.version+="-${{ github.ref_name }}-${{ github.sha }}"' package.json
141+ echo "tag=experimental" >> $GITHUB_OUTPUT
142+ fi
143+ echo "name=$(jq .name package.json)" >> $GITHUB_OUTPUT
144+ echo "version=$(jq .version package.json)" >> $GITHUB_OUTPUT
145+ - name : Publish package to NPM
146+ env :
147+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
148+ run : |
149+ corepack pnpm publish --access public --tag ${{ steps.package.outputs.tag }} --no-git-checks
150+ - name : Publish package to GitHub Package Registry
151+ env :
152+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
153+ run : |
154+ ./scripts/jqout.sh '.name="@${{ github.repository_owner }}/wasm"' package.json
155+ corepack pnpm publish --access public --tag ${{ steps.package.outputs.tag }} --no-git-checks
0 commit comments