Skip to content

Update GitHub Action, caching, local/ci scripts #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
- main
workflow_dispatch:

env:
IMAGE_NAME: ${{ github.repository }}

jobs:
publish:
runs-on: ubuntu-latest
Expand All @@ -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

Expand Down
3 changes: 0 additions & 3 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#!/bin/bash

# install cargo-component
cargo install cargo-component

# build our project
cargo component build --release
12 changes: 12 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -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
24 changes: 11 additions & 13 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -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
Loading