Skip to content

Commit de28fed

Browse files
committed
Update to automatically deploy Wasm binary
1 parent 841d307 commit de28fed

File tree

1 file changed

+40
-35
lines changed

1 file changed

+40
-35
lines changed

.github/workflows/deploy-to-github.yml

+40-35
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,28 @@ on:
33
push:
44
tags:
55
- '*'
6-
workflow_dispatch:
76

87
jobs:
98
deploy:
109
runs-on: ubuntu-latest
1110
env:
1211
EMSCRIPTEN_VERSION: '3.1.55'
1312
steps:
14-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
14+
- name: Clone gh-pages branch into nested directory
15+
uses: actions/checkout@v4
16+
with:
17+
ref: gh-pages
18+
path: gh-pages
19+
- name: Configure Git user
20+
run: |
21+
git config --global user.name "github-actions[bot]"
22+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
23+
- name: Get tag name
24+
id: tag
25+
run: |
26+
tag=$(basename "${{ github.ref }}")
27+
echo "tag=$tag" >> $GITHUB_OUTPUT
1528
- name: Set up Node
1629
uses: actions/setup-node@v3
1730
with:
@@ -27,38 +40,30 @@ jobs:
2740
- name: Build WASM binary
2841
run: npm run build-wasm
2942
- name: Deploy to GitHub Releases
30-
if: github.event_name != 'workflow_dispatch'
31-
uses: ncipollo/release-action@v1
32-
with:
33-
artifacts: tree-sitter-kotlin.wasm
34-
token: ${{ secrets.GITHUB_TOKEN }}
43+
run: |
44+
tag="${{ steps.tag.outputs.tag }}"
45+
gh release create "$tag" --title "$tag"
46+
gh release upload "$tag" tree-sitter-kotlin.wasm
47+
env:
48+
GH_TOKEN: ${{ github.token }}
49+
GH_REPO: ${{ github.repository }}
50+
- name: Deploy to GitHub Pages
51+
run: |
52+
sha="$(git rev-parse --short HEAD)"
53+
tag="${{ steps.tag.outputs.tag }}"
54+
55+
echo "==> Replacing Wasm binary..."
56+
rm -rf gh-pages/assets/tree-sitter-kotlin*
57+
mkdir -p "gh-pages/assets/tree-sitter-kotlin-$tag"
58+
cp tree-sitter-kotlin.wasm "gh-pages/assets/tree-sitter-kotlin-$tag"
59+
tree gh-pages/assets
3560
36-
# TODO: Update this to the new playground layout. This would
37-
# involve deploying the Wasm binary to
38-
#
39-
# assets/tree-sitter-kotlin-<version>/tree-sitter-kotlin.wasm
40-
#
41-
# and would also require rewriting the versions in the
42-
# index.html (both the reference to the parser binary and the
43-
# displayed version). Ideally this should be performed by a
44-
# script that generates the index.html automatically. Perhaps
45-
# we could even generate this to automatically download
46-
# web-tree-sitter and maybe even generate playground.js from
47-
# the upstream playground.
48-
#
49-
# Also, we would likely want to replace peaceiris/actions-gh-pages
50-
# with the `gh` command-line tool, which should already be
51-
# preinstalled in the runner.
61+
echo "==> Updating version on website..."
62+
sed -i "s|\(LANGUAGE_BASE_URL = \"\)[^\"]*\(\"\)|\1$tag\2|g" gh-pages/index.html
63+
sed -i "s|\(<span class=\"version\">\)[^<]*\(</span>\)|\1$tag\2|g" gh-pages/index.html
5264
53-
# - name: Set up folder for GitHub Pages deployment
54-
# run: |
55-
# mkdir public
56-
# cp tree-sitter-kotlin.wasm public/tree-sitter-parser.wasm
57-
# - name: Deploy to GitHub Pages
58-
# uses: peaceiris/actions-gh-pages@v3
59-
# with:
60-
# github_token: ${{ secrets.GITHUB_TOKEN }}
61-
# publish_dir: ./public
62-
# keep_files: true
63-
# user_name: 'github-actions[bot]'
64-
# user_email: 'github-actions[bot]@users.noreply.github.com'
65+
echo "==> Committing and pushing gh-pages branch..."
66+
cd gh-pages
67+
git add .
68+
git commit -m "Deploy tree-sitter-kotlin $tag ($sha)"
69+
git push

0 commit comments

Comments
 (0)