Skip to content

Commit

Permalink
add action for auto publish to pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Strosel committed Aug 20, 2020
1 parent b33e0b7 commit 6173c67
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: A workflow to build wasm for github pages
on:
push:
tags:
- v*

jobs:
build:
name: Wasm build/deploy action
runs-on: ubuntu-latest
steps:
-
uses: actions/checkout@v1
-
uses: ./wasm-action
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15 changes: 15 additions & 0 deletions wasm-action/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM golang

RUN go get -d github.com/strosel/treman
RUN go get gioui.org/cmd/gogio

RUN apt-get update
RUN apt-get install --yes \
libxkbcommon-x11-dev \
libgles2-mesa-dev \
curl \
jq

ADD entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
11 changes: 11 additions & 0 deletions wasm-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "Build + Publish wasm version"
description: "Build wasm and publish to github pages"
author: "[email protected]"

runs:
using: "docker"
image: "Dockerfile"

branding:
icon: "mic"
color: "purple"
42 changes: 42 additions & 0 deletions wasm-action/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash


REPO="treman"
GITHUB_PATH="strosel/${REPO}"
API_URL="https://api.github.com/repos/${GITHUB_PATH}"

gogio -target js -o $REPO github.com/$GITHUB_PATH

SHA=$(curl -X GET \
"${API_URL}/git/trees/pages" | \
jq '.tree | map(select(.path == "main.wasm")) | .[0]? | .sha')

echo "{ \
\"message\": \"new release\",\
\"branch\": \"pages\",\
\"content\": \"$(openssl base64 -A -in ./$REPO/main.wasm)\",\
\"sha\": ${SHA}
}" > data.txt

tmp=$(mktemp)

RES=$(curl \
-X PUT \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${GITHUB_TOKEN}" \
-d @data.txt \
--write-out "%{http_code}" \
--output $tmp \
"${API_URL}/contents/main.wasm")

if [ "$?" -ne 0 ]; then
echo "Curl error"
cat $tmp
exit 1
fi

if [ $RES -ne 200 ]; then
echo "HTTP error ${RES}"
cat $tmp
exit 1
fi

0 comments on commit 6173c67

Please sign in to comment.