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 30, 2024
1 parent c1ab6cc commit 541d5fa
Show file tree
Hide file tree
Showing 10 changed files with 430 additions and 8 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
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 }}
14 changes: 12 additions & 2 deletions .github/workflows/ci_.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,21 @@ 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 }}
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
4 changes: 2 additions & 2 deletions .github/workflows/ci_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ jobs:
cache-key: ${{ format('e2e-wash-{0}', matrix.wash) }}

- name: Install `wash` CLI
uses: taiki-e/install-action@ed8c79bccf0b1cb1544a358f81684d3acaa5133f
uses: taiki-e/install-action@acd25891978b4cdaebd139d3efef606d26513b14 # v2.47.0
with:
tool: wash-cli@${{ matrix.wash }}
tool: wash@${{ matrix.wash }}

- name: Run Playwright Tests
run: yarn test:e2e
Expand Down
94 changes: 94 additions & 0 deletions .github/workflows/examples_.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
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.version.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: Install `wash` CLI
uses: taiki-e/install-action@acd25891978b4cdaebd139d3efef606d26513b14 # v2.47.0
with: { tool: wash }

- name: Get Installed wash Version
id: version
# Update to use json output after https://github.com/wasmCloud/wasmCloud/issues/3884 is resolved
run: |
# Get the installed wash version
echo "version=$(wash -V | head -n 1 | awk '{gsub(/v/, ""); print $2}')" >> $GITHUB_OUTPUT
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 541d5fa

Please sign in to comment.