From d7abc026696a78b9dd394ae7ca9a7b5b203be6ca Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Fri, 16 Aug 2024 14:42:43 +0100 Subject: [PATCH] Initial extensible check workflow test --- .github/ci.json | 8 ++ .github/workflows/check.yml | 126 ++++++++++++++++++ .gitignore | 1 + .../package.json | 1 + .../plugin-cutout-library-web/package.json | 1 + .../package.json | 1 + packages/plugin-utils/package.json | 1 + 7 files changed, 139 insertions(+) create mode 100644 .github/ci.json create mode 100644 .github/workflows/check.yml diff --git a/.github/ci.json b/.github/ci.json new file mode 100644 index 0000000..85d6506 --- /dev/null +++ b/.github/ci.json @@ -0,0 +1,8 @@ +{ + "build-and-test": [ + "plugin-background-removal-web", + "plugin-cutout-library-web", + "plugin-remote-asset-source-web", + "plugin-utils" + ] +} diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..104e4d1 --- /dev/null +++ b/.github/workflows/check.yml @@ -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" diff --git a/.gitignore b/.gitignore index 04666a4..7678969 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ packages/*/dist examples/*/dist .env.local .nvmrc +*.tgz .DS_Store yarn-error.log diff --git a/packages/plugin-background-removal-web/package.json b/packages/plugin-background-removal-web/package.json index e08e006..92b02d3 100644 --- a/packages/plugin-background-removal-web/package.json +++ b/packages/plugin-background-removal-web/package.json @@ -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", diff --git a/packages/plugin-cutout-library-web/package.json b/packages/plugin-cutout-library-web/package.json index e2174fb..09f53a0 100644 --- a/packages/plugin-cutout-library-web/package.json +++ b/packages/plugin-cutout-library-web/package.json @@ -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", diff --git a/packages/plugin-remote-asset-source-web/package.json b/packages/plugin-remote-asset-source-web/package.json index eed62c9..493563d 100644 --- a/packages/plugin-remote-asset-source-web/package.json +++ b/packages/plugin-remote-asset-source-web/package.json @@ -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", diff --git a/packages/plugin-utils/package.json b/packages/plugin-utils/package.json index 894d037..572ecb4 100644 --- a/packages/plugin-utils/package.json +++ b/packages/plugin-utils/package.json @@ -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\"",