Skip to content

Commit

Permalink
chore(ci): add examples workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Heywood <[email protected]>
  • Loading branch information
lachieh committed Dec 26, 2024
1 parent cc766ff commit 2ea6dda
Show file tree
Hide file tree
Showing 10 changed files with 480 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## GitHub CI

.github @wasmCloud/ci-maintainers
.github/** @wasmCloud/ci-maintainers
.github/CODEOWNERS @wasmCloud/org-maintainers

## Projects
Expand Down
54 changes: 54 additions & 0 deletions .github/actions/cached-wash-install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: crate-versions

description: |
Get the 3 latest versions of the specified crate from crates.io.
branding:
icon: settings
color: blue

inputs:
version:
description: Version of wash-cli to install and cache
default: 'latest'

outputs:
version:
description: Selected wash-cli to install and cache
value: ${{ steps.versions.outputs.latest }}

runs:
using: composite

steps:
- name: Get Latest wash-cli Version
if: ${{ inputs.version == 'latest' }}
uses: ./.github/actions/crate-versions
id: versions
with:
crate: wash-cli

- name: Set Version
shell: bash
run: |
# Set WASH_VERSION
echo "WASH_VERSION=${{ inputs.version == 'latest' && steps.versions.outputs.latest || inputs.version }}" >> $GITHUB_ENV
- name: Restore Cache
id: restore
uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
key: ${{ runner.os }}-restore-wash-cli-${{ env.WASH_VERSION }}
path: ~/.cargo/bin/wash

- name: Install wash-cli
if: ${{ steps.restore.outputs.cache-hit != 'true' }}
uses: taiki-e/install-action@8484225d9734e230a8bf38421a4ffec1cc249372 # v2.46.20
with:
tool: ${{ format('wash-cli@{0}', env.WASH_VERSION) }}

- uses: actions/cache/save@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
if: ${{ always() && steps.restore.outputs.cache-hit != 'true' }}
with:
key: ${{ steps.restore.outputs.cache-primary-key }}
path: ~/.cargo/bin/wash
9 changes: 8 additions & 1 deletion .github/actions/crate-versions/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,24 @@ runs:
- name: Fetch crate versions
id: fetch_versions
run: |
CRATE_NAME=${{ inputs.crate }}
# Fetch the crate information from crates.io
CRATE_NAME=${{ inputs.crate }}
RESPONSE=$(curl -s -H "User-Agent: wasmCloud-github-actions/1.0 (slack.wasmcloud.com)" "https://crates.io/api/v1/crates/$CRATE_NAME")
# Extract all versions that are not yanked
ALL_VERSIONS=$(echo $RESPONSE | jq -c -r '.versions | map(select(.yanked | not)) | map(.num) | map(select(test("^[0-9]+\\.[0-9]+\\.[0-9]+$")))')
# Extract the latest 3 major versions (or minor versions if the crate is in the 0.x range)
LAST_3_VERSIONS=$(echo $ALL_VERSIONS | jq -c -r 'unique_by(if . | startswith("0.") then split(".")[1] else split(".")[0] end) | sort_by(split(".") | map(tonumber)) | reverse | .[0:3]')
echo "versions=$LAST_3_VERSIONS" >> $GITHUB_OUTPUT
echo "latest=$(echo $LAST_3_VERSIONS | jq -r '.[0]')" >> $GITHUB_OUTPUT
echo "::group::Latest 3 versions of $CRATE_NAME"
echo $LAST_3_VERSIONS | jq
echo "::endgroup::"
shell: bash

outputs:
versions:
description: The latest 3 major versions of the crate.
value: ${{ steps.fetch_versions.outputs.versions }}
latest:
description: The latest version of the crate.
value: ${{ steps.fetch_versions.outputs.latest }}
5 changes: 5 additions & 0 deletions .github/actions/ts-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ runs:
cache-dependency-path: ${{ inputs.working-directory }}/yarn.lock
cache: yarn

- name: Skip .npmrc File Configuration
if: ${{ inputs.npm-token == '' }}
shell: bash
run: echo "Skipping NPM token setup"

- name: Configure .npmrc File
if: ${{ inputs.npm-token != '' }}
shell: bash
Expand Down
35 changes: 35 additions & 0 deletions .github/actions/wash-versions/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: crate-versions

description: |
Get the latest versions of the `wash` CLI and `wash` Playwright tests
branding:
icon: settings
color: blue

inputs:
crate:
description: Name of the crate of which to fetch versions for
required: true

runs:
using: composite

steps:
- name: Fetch crate versions
id: fetch_versions
run: |
CRATE_NAME=${{ inputs.crate }}
# Fetch the crate information from crates.io
RESPONSE=$(curl -s -H "User-Agent: wasmCloud-github-actions/1.0 (slack.wasmcloud.com)" "https://crates.io/api/v1/crates/$CRATE_NAME")
# Extract all versions that are not yanked
ALL_VERSIONS=$(echo $RESPONSE | jq -c -r '.versions | map(select(.yanked | not)) | map(.num) | map(select(test("^[0-9]+\\.[0-9]+\\.[0-9]+$")))')
# Extract the latest 3 major versions (or minor versions if the crate is in the 0.x range)
LAST_3_VERSIONS=$(echo $ALL_VERSIONS | jq -c -r 'unique_by(if . | startswith("0.") then split(".")[1] else split(".")[0] end) | sort_by(split(".") | map(tonumber)) | reverse | .[0:3]')
echo "versions=$LAST_3_VERSIONS" >> $GITHUB_OUTPUT
shell: bash

outputs:
versions:
description: The latest 3 major versions of the crate.
value: ${{ steps.fetch_versions.outputs.versions }}
19 changes: 14 additions & 5 deletions .github/workflows/ci_.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- main

permissions:
contents: read
contents: write

concurrency:
group: washboard-${{ github.event.pull_request.number || github.ref }}
Expand All @@ -27,11 +27,20 @@ jobs:
release:
uses: ./.github/workflows/ci_release.yml
# Only run on main repo, don't try to release on forks
if: github.repository == 'wasmCloud/typescript'
# Also only run on pushes to main branch, i.e. PRs and merge groups should not run this step
if: |
(github.repository == 'wasmCloud/typescript') &&
(github.event_name == 'push' && github.ref == 'refs/heads/main')
needs: [build, test]
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
secrets: inherit
permissions:
contents: write # Needed to commit changesets
pull-requests: write # Needed to create pull requests
id-token: write # Needed for npm provenance
id-token: write # Needed for npm provenance

ci-check:
needs: [build, test]
if: ${{ always() }}
uses: ./.github/workflows/workflow_check.yml
with:
pass-condition: ${{ contains(needs.*.result, 'failure') == false }}
2 changes: 0 additions & 2 deletions .github/workflows/ci_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ jobs:

- name: Setup Node, Yarn, and Turbo
uses: ./.github/actions/ts-setup
with:
npm-token: ${{ secrets.NPM_TOKEN }}

- name: Build
run: yarn turbo build
Expand Down
87 changes: 87 additions & 0 deletions .github/workflows/examples_.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Examples

on:
push:
branches:
- main
tags:
- '**'
pull_request:
branches:
- main

permissions:
contents: read

jobs:
meta:
runs-on: ubuntu-latest
outputs:
changes: ${{ steps.changes.outputs.changed_keys }}
changed-components: ${{ contains(steps.changes.outputs.changed_keys, 'components') }}
changed-providers: ${{ contains(steps.changes.outputs.changed_keys, 'providers') }}
changed-ci: ${{ contains(steps.changes.outputs.changed_keys, 'ci') }}
wash-version: ${{ steps.versions.outputs.version }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Check for changes
id: changes
uses: tj-actions/changed-files@bab30c2299617f6615ec02a68b9a40d10bd21366 # v45.0.5
with:
matrix: true
dir_names: true
dir_names_max_depth: 3
files_yaml: |
ci:
- .github/workflows/examples_.yml
- .github/workflows/examples_component.yml
- .github/workflows/examples_provider.yml
components:
- examples/components/**
providers:
- examples/providers/**
- name: Fetch/Cache Latest wash Version
id: versions
uses: ./.github/actions/cached-wash-install

components:
name: ${{ format('example:component:{0}', matrix.project.folder) }}
needs: [meta]
if: needs.meta.outputs.changed-ci == 'true' || needs.meta.outputs.changed-components == 'true'
secrets: inherit
uses: ./.github/workflows/examples_component.yml
with:
folder: ${{ matrix.project.folder }}
wasm-bin: ${{ matrix.project.wasm-bin }}
test-command: ${{ matrix.project.test-command }}
force: ${{ needs.meta.outputs.changed-ci == 'true' }}
wash-version: ${{ needs.meta.outputs.wash-version }}
strategy:
fail-fast: false
matrix:
project:
# Sample matrix entry for examples
# - folder: http-hello-world # Folder name of the example within examples/components/*
# wasm-bin: dist/http-hello-world.wasm # Path to the wasm binary after build
# test-command: TEST_RESULT=1 # Some command that will set TEST_RESULT to 0 or 1

- folder: http-hello-world
wasm-bin: http_hello_world_s.wasm
test-command: |
RESPONSE=$(curl http://127.0.0.1:8000 || echo '')
[[ "$RESPONSE" == 'Hello from Typescript!' ]] && TEST_RESULT=1 || TEST_RESULT=0
- folder: http-password-checker
wasm-bin: http_password_checker_s.wasm
test-command: |
RESPONSE=$(curl http://127.0.0.1:8000/api/v1/check -d '{"value": "test"}' | jq -r '.status' || echo '')
[[ "$RESPONSE" == 'success' ]] && TEST_RESULT=1 || TEST_RESULT=0
examples-check:
needs: [components]
if: ${{ always() }}
uses: ./.github/workflows/workflow_check.yml
with:
pass-condition: ${{ contains(needs.*.result, 'failure') == false }}
Loading

0 comments on commit 2ea6dda

Please sign in to comment.