diff --git a/.github/actions/install/action.yml b/.github/actions/install/action.yml new file mode 100644 index 0000000..501f28a --- /dev/null +++ b/.github/actions/install/action.yml @@ -0,0 +1,20 @@ +name: Install +description: Install pnpm dependencies +runs: + using: "composite" + steps: + - name: Install pnpm + uses: pnpm/action-setup@v4 + with: + version: 9 + run_install: false + + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version: 18 + cache: "pnpm" + + - name: Install dependencies + shell: bash + run: pnpm install --frozen-lockfile diff --git a/.github/workflows/audit-dependencies.yml b/.github/workflows/audit-dependencies.yml index df62eac..044c104 100644 --- a/.github/workflows/audit-dependencies.yml +++ b/.github/workflows/audit-dependencies.yml @@ -11,23 +11,8 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 5 steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Install pnpm - uses: pnpm/action-setup@v4 - with: - version: 9 - run_install: false - - - name: Install Node.js - uses: actions/setup-node@v4 - with: - node-version: 18 - cache: "pnpm" - - - name: Install dependencies - run: pnpm install --frozen-lockfile + - name: Install + uses: ./.github/actions/install - name: Audit dependencies run: pnpm audit diff --git a/.github/workflows/preview-pr.yml b/.github/workflows/preview-pr.yml new file mode 100644 index 0000000..3887c8c --- /dev/null +++ b/.github/workflows/preview-pr.yml @@ -0,0 +1,56 @@ +name: Preview PR +on: + pull_request: + types: + - opened + - closed + - reopened + - synchronize + +jobs: + wait: + name: Wait for checks + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + # This is a separate file that simply waits for the other checks to complete because + # we don't want to run duplicate checks for pr + push events. + # Checks and builds run on all branches (on _push_) but this workflow runs only on PR events. + # If you know a smarter way, let us now. + - name: Wait for other checks to succeed + if: github.event.action != 'closed' + uses: lewagon/wait-on-check-action@v1.3.4 + with: + ref: ${{ github.event.pull_request.head.sha }} + check-name: "Build samples and documentation" + repo-token: ${{ secrets.GITHUB_TOKEN }} + wait-interval: 10 + + deploy: + name: Preview PR + runs-on: ubuntu-latest + concurrency: preview-${{ github.ref }} + timeout-minutes: 5 + needs: wait + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Download latest build artifact + run: | + WORKFLOW_RUN=$(gh run list -c ${{ github.event.pull_request.head.sha }} -w "test-and-build.yml" -e push --json databaseId --limit 1 | jq .[0].databaseId -r) + echo "Latest workflow run: $WORKFLOW_RUN" + + mkdir site && cd site; + + echo "Downloading build artifact" + gh run download $WORKFLOW_RUN -n build + echo "Download successful:" + ls -alh + env: + GH_TOKEN: ${{ github.token }} + + - name: Deploy PR Preview + uses: rossjrw/pr-preview-action@v1.4.7 + with: + source-dir: ./site/www/ diff --git a/.github/workflows/test-and-build.yml b/.github/workflows/test-and-build.yml index 008a78c..4331885 100644 --- a/.github/workflows/test-and-build.yml +++ b/.github/workflows/test-and-build.yml @@ -4,32 +4,18 @@ on: push: pull_request: jobs: - test: + checks: # Don't run for pull requests from this repository to avoid duplicate builds (push also triggers build). if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name - name: "Test and Build" + name: "Run quality checks" runs-on: ubuntu-latest - timeout-minutes: 15 - permissions: - contents: write + timeout-minutes: 5 steps: - name: Checkout uses: actions/checkout@v4 - - name: Install pnpm - uses: pnpm/action-setup@v4 - with: - version: 9 - run_install: false - - - name: Install Node.js - uses: actions/setup-node@v4 - with: - node-version: 18 - cache: "pnpm" - - - name: Install dependencies - run: pnpm install --frozen-lockfile + - name: Install + uses: ./.github/actions/install - name: Lint dependencies run: pnpm lint-shared-versions @@ -37,13 +23,23 @@ jobs: - name: Run tests run: pnpm ci:test + build_site: + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name + name: "Build samples and documentation" + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install + uses: ./.github/actions/install + - name: Build samples run: pnpm build - - name: Build packages - run: pnpm build-packages - - name: Build API documentation + if: github.ref == 'refs/heads/main' run: pnpm build-docs - name: Upload artifact @@ -53,19 +49,39 @@ jobs: path: dist/ retention-days: ${{ github.ref == 'refs/heads/main' && 7 || 1 }} + build_packages: + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name + name: "Build packages" + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install + uses: ./.github/actions/install + + - name: Build packages + run: pnpm build-packages + call_version: if: github.ref == 'refs/heads/main' name: "Publish or create version PR" uses: "./.github/workflows/version.yml" - needs: test + needs: + - checks + - build_packages secrets: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} deploy: if: github.ref == 'refs/heads/main' + name: "Deploy site" runs-on: ubuntu-latest timeout-minutes: 5 - needs: test + needs: + - checks + - build_site steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml index f0868d1..ae30c2a 100644 --- a/.github/workflows/version.yml +++ b/.github/workflows/version.yml @@ -17,21 +17,8 @@ jobs: with: fetch-depth: 0 - - name: Install pnpm - uses: pnpm/action-setup@v4 - with: - version: 9 - run_install: false - - - name: Install Node.js - uses: actions/setup-node@v4 - with: - node-version: 18 - registry-url: "https://registry.npmjs.org" - cache: "pnpm" - - - name: Install dependencies - run: pnpm install --frozen-lockfile + - name: Install + uses: ./.github/actions/install - name: Create Release Pull Request or Publish to npm uses: changesets/action@v1