Skip to content

Commit

Permalink
Initial extensible check workflow test
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenraven committed Aug 16, 2024
1 parent f2a2d01 commit d7abc02
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"build-and-test": [
"plugin-background-removal-web",
"plugin-cutout-library-web",
"plugin-remote-asset-source-web",
"plugin-utils"
]
}
126 changes: 126 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: Build & Test
on:
push:
branches: [main]
pull_request:
branches: [main]

permissions:
contents: read
checks: write
statuses: write

jobs:
configure:
name: Configure the build
runs-on: ubuntu-24.04
steps:
- name: Create the commit status check
shell: bash
env:
GITHUB_TOKEN: ${{ github.token }}
STATUS_REPO: ${{ github.repository }}
STATUS_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
STATUS_STATE: pending
STATUS_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
set -x
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${STATUS_REPO}/statuses/${STATUS_SHA}" \
-f "state=${STATUS_STATE}" \
-f "target_url=${STATUS_URL}" \
-f "description=PR Check Workflow" \
-f "context=IMG.LY"
- uses: actions/checkout@v4
with:
fetch-depth: 1
sparse-checkout: |
.github
- name: Construct build matrix
id: construct_matrix
shell: bash
run: |
set -x
jq --compact-output --raw-output '."build-and-test" | tostring | "matrix_packages=" + .' .github/ci.json | tee -a "$GITHUB_OUTPUT"
outputs:
matrix_packages: ${{ steps.construct_matrix.outputs.matrix_packages }}

test:
name: Test ${{ matrix.package }} for Node ${{ matrix.node-version }}
needs: [configure]
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
node-version: [20.x, 21.x]
package: ${{ fromJson(needs.configure.outputs.matrix_packages) }}
env:
IMGLY_PACKAGE_DIR: ${{ matrix.package == '.' && github.workspace || format('{0}/packages/{1}', github.workspace, matrix.package) }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
lfs: true
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- name: Install dependencies
working-directory: ${{ env.IMGLY_PACKAGE_DIR }}
shell: bash
run: yarn install
- name: Run checks
working-directory: ${{ env.IMGLY_PACKAGE_DIR }}
shell: bash
run: yarn run check:all
- name: Build
working-directory: ${{ env.IMGLY_PACKAGE_DIR }}
shell: bash
run: yarn run build
- name: Test
working-directory: ${{ env.IMGLY_PACKAGE_DIR }}
shell: bash
run: yarn run test
- name: Package
if: success() || failure()
working-directory: ${{ env.IMGLY_PACKAGE_DIR }}
shell: bash
run: yarn pack
- name: Upload
if: success() || failure()
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.package }}-ci-node${{ matrix.node-version }}.tgz.zip
path: '${{ env.IMGLY_PACKAGE_DIR }}/*.tgz'
if-no-files-found: ignore
overwrite: true

summary:
name: Summary test status
needs: [test]
if: success() || failure()
runs-on: ubuntu-24.04
steps:
- name: Update the commit status check
shell: bash
env:
GITHUB_TOKEN: ${{ github.token }}
STATUS_REPO: ${{ github.repository }}
STATUS_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
STATUS_STATE: ${{ needs.test.result == 'success' && 'success' || 'failure' }}
STATUS_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
set -x
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${STATUS_REPO}/statuses/${STATUS_SHA}" \
-f "state=${STATUS_STATE}" \
-f "target_url=${STATUS_URL}" \
-f "description=PR Check Workflow" \
-f "context=IMG.LY"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ packages/*/dist
examples/*/dist
.env.local
.nvmrc
*.tgz

.DS_Store
yarn-error.log
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-background-removal-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"clean": "npx rimraf dist",
"purge": "npx rimraf node_modules",
"build": "npm run clean && node scripts/build.mjs",
"test": "echo No tests",
"dev": "node scripts/watch.mjs",
"dev:wait": "npx wait-on ./dist/index.mjs ./dist/index.d.ts --timeout 30000",
"dev:types": "tsc --emitDeclarationOnly --watch --preserveWatchOutput",
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-cutout-library-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"clean": "npx rimraf dist",
"purge": "npx rimraf node_modules",
"build": "npm run clean && node scripts/build.mjs && cp -r assets dist/",
"test": "echo No tests",
"dev": "node scripts/watch.mjs",
"dev:wait": "npx wait-on ./dist/index.mjs ./dist/index.d.ts --timeout 30000",
"dev:types": "tsc --emitDeclarationOnly --watch --preserveWatchOutput",
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-remote-asset-source-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"clean": "npx rimraf dist",
"purge": "npx rimraf node_modules",
"build": "npm run clean && node scripts/build.mjs",
"test": "echo No tests",
"dev": "npm run clean && node scripts/watch.mjs",
"dev:wait": "npx wait-on ./dist/index.mjs ./dist/index.d.ts --timeout 30000",
"dev:types": "tsc --emitDeclarationOnly --watch --preserveWatchOutput",
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"clean": "npx rimraf dist",
"purge": "npx rimraf node_modules",
"build": "npm run clean && node scripts/build.mjs",
"test": "echo No tests",
"dev": "node scripts/watch.mjs",
"dev:wait": "npx wait-on ./dist/index.mjs ./dist/index.d.ts --timeout 30000",
"check:all": "concurrently -n lint,type,pretty \"yarn check:lint\" \"yarn check:types\" \"yarn check:pretty\"",
Expand Down

0 comments on commit d7abc02

Please sign in to comment.