diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9c343c8..666f51a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,6 +9,9 @@ on: - main workflow_dispatch: +env: + IMAGE_NAME: ${{ github.repository }} + jobs: publish: runs-on: ubuntu-latest @@ -17,6 +20,31 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Cache cargo bin + id: cache-cargo + uses: actions/cache@v3 + env: + cache-name: cache-cargo-bin + with: + path: ~/.cargo/bin + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('scripts/install.sh') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - if: ${{ steps.cache-cargo.outputs.cache-hit != 'true' }} + name: Run install script + continue-on-error: false + run: bash scripts/install.sh + - name: Run build script run: bash scripts/build.sh diff --git a/scripts/build.sh b/scripts/build.sh index 3ab7e32..66beb42 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,7 +1,4 @@ #!/bin/bash -# install cargo-component -cargo install cargo-component - # build our project cargo component build --release diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100644 index 0000000..9483f30 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,12 @@ +# setup dir +mkdir -p tmp +cd tmp + +# install wkg +git clone https://github.com/bytecodealliance/wasm-pkg-tools +cd wasm-pkg-tools/crates/wkg +cargo install --path . +cd ../../../../ + +# install cargo-component +cargo install cargo-component --force --version 0.16.0 diff --git a/scripts/publish.sh b/scripts/publish.sh index a949ead..ef227d9 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -1,18 +1,16 @@ #!/bin/bash -# setup dir -mkdir -p tmp -cd tmp +# not running in github actions? use gh cli to login, etc, locally +if [ "$GITHUB_ACTIONS" != "true" ]; then + # login to the registry + # if running locally, we may need to: + # gh auth refresh -h github.com -s write:packages,read:packages + gh auth token | docker login ghcr.io --username YOURUSERNAME --password-stdin + GH_USER=$(gh api user --jq '.login') + IMAGE_NAME="${GH_USER}/rust-wasi-hello" +fi -# install wkg -git clone https://github.com/bytecodealliance/wasm-pkg-tools -cd wasm-pkg-tools -cargo install --path . - -# login to the registry -gh auth token | docker login ghcr.io --username yoshuawuyts --password-stdin - -# publish using wkg PROJECT_NAME="rust_wasi_hello" -REGISTRY_REFERENCE="ghcr.io/yoshuawuyts/rust-wasi-hello:latest" +REGISTRY_REFERENCE="ghcr.io/${IMAGE_NAME}:latest" + wkg oci push $REGISTRY_REFERENCE target/wasm32-wasip1/release/$PROJECT_NAME.wasm