diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ee704f8..310e474 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,9 +5,19 @@ on: branches: ["main"] pull_request: branches: ["main"] + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: "pages" + cancel-in-progress: false jobs: - check: + build-test-webapi: runs-on: ubuntu-latest steps: - name: Checkout @@ -22,11 +32,24 @@ jobs: uses: actions/setup-node@v4 with: node-version: 22 + cache: 'npm' + cache-dependency-path: | + webapi_gen/package-lock.json + tests/package-lock.json - name: Install npm dependencies working-directory: webapi_gen run: npm ci + - name: Cache MoonBit packages + uses: actions/cache@v4 + with: + path: | + .mooncakes + webapi_gen/.mooncakes + examples/.mooncakes + key: mooncakes-${{ runner.os }}-${{ hashFiles('moon.mod.json', 'webapi_gen/moon.mod.json', 'examples/moon.mod.json') }} + - name: Install MoonBit dependencies run: | moon version --all @@ -42,27 +65,6 @@ jobs: working-directory: webapi_gen run: moon test - examples: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up MoonBit - run: | - curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash - echo "$HOME/.moon/bin" >> $GITHUB_PATH - - - name: Set up Node.js - uses: actions/setup-node@v4 - with: - node-version: 22 - - - name: Install MoonBit dependencies - run: | - moon version --all - moon update - - name: Build examples (JS) working-directory: examples run: moon build --target js --release @@ -71,12 +73,50 @@ jobs: working-directory: examples run: moon build --target wasm-gc --release + - name: Cache Playwright browsers + id: cache-playwright + uses: actions/cache@v4 + with: + path: ~/.cache/ms-playwright + key: playwright-${{ runner.os }}-${{ hashFiles('tests/package-lock.json') }} + - name: Install Playwright dependencies working-directory: tests run: | npm ci - npx playwright install chromium + npx playwright install chromium --with-deps - name: Run Playwright tests working-directory: tests run: npx playwright test --workers 2 + + - name: Prepare site + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + run: | + mkdir -p _site/src + cp -rL examples _site/examples + rm -rf _site/examples/.mooncakes _site/examples/_build + cp src/webapi.mjs _site/src/ + echo '' > _site/index.html + + - name: Setup Pages + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + uses: actions/configure-pages@v5 + + - name: Upload pages artifact + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + uses: actions/upload-pages-artifact@v3 + with: + path: '_site' + + deploy: + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build-test-webapi + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml deleted file mode 100644 index f893095..0000000 --- a/.github/workflows/pages.yml +++ /dev/null @@ -1,58 +0,0 @@ -# Deploy examples to GitHub Pages -name: Deploy to GitHub Pages - -on: - push: - branches: ["main"] - workflow_dispatch: - -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages -permissions: - contents: read - pages: write - id-token: write - -# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. -concurrency: - group: "pages" - cancel-in-progress: false - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up MoonBit - run: | - curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash - echo "$HOME/.moon/bin" >> $GITHUB_PATH - - - name: Install MoonBit dependencies - run: | - moon version --all - moon update - - - name: Build examples - working-directory: examples - run: moon build --target js --release - - - name: Setup Pages - uses: actions/configure-pages@v5 - - - name: Upload artifact - uses: actions/upload-pages-artifact@v3 - with: - path: 'examples' - - deploy: - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - runs-on: ubuntu-latest - needs: build - steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v4 diff --git a/examples/index.html b/examples/index.html index f0ea09c..ad3bffd 100644 --- a/examples/index.html +++ b/examples/index.html @@ -9,24 +9,28 @@ h1 { font-weight: 300; letter-spacing: 2px; } ul { list-style: none; padding: 0; } li { margin: 1rem 0; } - a { color: #4a90d9; text-decoration: none; font-size: 1.1rem; } + .name { font-size: 1.1rem; margin-right: 0.5rem; } + a { color: #4a90d9; text-decoration: none; } a:hover { text-decoration: underline; } + .targets { font-size: 0.9rem; } + .targets a { margin: 0 0.15rem; } + .sep { color: #999; }