From 5c24ea4f7ed03d67cdbe1d45e25c8c30eb1d0ad6 Mon Sep 17 00:00:00 2001 From: Maxwell Brown Date: Sat, 2 Dec 2023 14:30:41 -0500 Subject: [PATCH] Improve CI with Nix (#405) --- .github/actions/setup/action.yml | 24 +++++------------------- .github/workflows/build.yml | 8 ++++---- .github/workflows/check.yml | 8 ++++++-- .github/workflows/pages.yml | 2 +- .github/workflows/snapshot.yml | 22 +++++++++++----------- .github/workflows/test.yml | 5 +---- 6 files changed, 28 insertions(+), 41 deletions(-) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 0814ff1..7e67ec8 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -8,28 +8,14 @@ inputs: runs: using: composite steps: - - name: Install nix - uses: cachix/install-nix-action@v22 - with: - nix_path: nixpkgs=channel:nixos-unstable - extra_nix_config: | - auto-optimise-store = true - keep-outputs = true - keep-derivations = true - - name: Cache nix - uses: cachix/cachix-action@v12 - with: - name: effect-ts - authToken: ${{ inputs.cachixAuthToken }} - - name: Setup direnv - uses: HatsuneMiku3939/direnv-action@v1 - with: - direnvVersion: 2.32.2 + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main - name: Get pnpm store directory id: pnpm-cache shell: bash run: | - echo "::set-output name=pnpm_cache_dir::$(pnpm store path)" + echo "::set-output name=pnpm_cache_dir::$(nix develop --command -- pnpm store path)" - uses: actions/cache@v3 name: Cache pnpm with: @@ -39,4 +25,4 @@ runs: ${{ runner.os }}-pnpm-store- - name: Install dependencies shell: bash - run: pnpm install --ignore-scripts + run: nix develop --command -- pnpm install --ignore-scripts diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 73300e8..3ff68fb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,15 +23,15 @@ jobs: uses: ./.github/actions/setup with: cachixAuthToken: ${{ secrets.CACHIX_AUTH_TOKEN }} - - run: pnpm build + - run: nix develop --command -- pnpm build - name: Check source state - run: git add src && git diff-index --cached HEAD --exit-code src - - run: pnpm circular + run: nix develop --command -- git add src && git diff-index --cached HEAD --exit-code src + - run: nix develop --command -- pnpm circular - name: Create Release Pull Request or Publish if: github.event_name == 'push' && github.ref == 'refs/heads/main' uses: changesets/action@v1 with: - publish: pnpm changeset publish + publish: nix develop --command -- pnpm changeset publish env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 09714c2..8045567 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -21,5 +21,9 @@ jobs: uses: ./.github/actions/setup with: cachixAuthToken: ${{ secrets.CACHIX_AUTH_TOKEN }} - - run: pnpm check - - run: pnpm lint + - name: Check flake.lock + uses: DeterminateSystems/flake-checker-action@main + with: + fail-mode: true + - run: nix develop --command -- pnpm check + - run: nix develop --command -- pnpm lint diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 0a5654b..05d430f 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -23,7 +23,7 @@ jobs: uses: ./.github/actions/setup with: cachixAuthToken: ${{ secrets.CACHIX_AUTH_TOKEN }} - - run: pnpm docgen + - run: nix develop --command -- pnpm docgen - name: Build pages Jekyll if: github.event_name == 'push' && github.ref == 'refs/heads/main' uses: actions/jekyll-build-pages@v1 diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index bb408c8..c53bf0b 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -42,19 +42,19 @@ jobs: issue-number: ${{ github.event.issue.number }} body: | **Alright @${{ github.actor }}, I'm working on the snapshot!** - + You can follow the progress [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}). - name: Checkout default branch uses: actions/checkout@v2 - + - name: Checkout pull request branch run: gh pr checkout ${{ github.event.issue.number }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Get current branch name - id: branch + id: branch run: echo "branch=$(git branch --show-current)" >> $GITHUB_OUTPUT - name: Retrieve changeset entries @@ -68,24 +68,24 @@ jobs: - name: Exit pre-release mode if: ${{ hashFiles('.changeset/pre.json') != '' }} - run: pnpm changeset pre exit + run: nix develop --command -- pnpm changeset pre exit - name: Version snapshot - run: pnpm changeset version --snapshot ${{ steps.command.outputs.snapshot }} | grep -q "All files have been updated" + run: nix develop --command -- pnpm changeset version --snapshot ${{ steps.command.outputs.snapshot }} | grep -q "All files have been updated" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Build snapshot - run: pnpm build - + run: nix develop --command -- pnpm build + - name: Set registry config - run: pnpm config set --location project "//registry.npmjs.org/:_authToken" "${{ secrets.NPM_TOKEN }}" + run: nix develop --command -- pnpm config set --location project "//registry.npmjs.org/:_authToken" "${{ secrets.NPM_TOKEN }}" - name: Publish snapshot id: snapshot run: | # Publish and extract published tags from stdout. - output=$(pnpm changeset publish --tag ${{ steps.command.outputs.snapshot }} --no-git-tag) + output=$(nix develop --command -- pnpm changeset publish --tag ${{ steps.command.outputs.snapshot }} --no-git-tag) output=$(echo "$output" | awk '/packages published successfully:/{flag=1; next} flag') output=$(echo "$output" | grep -o '@[^ ]*' | awk '{print "\"" $0 "\""}' | paste -sd ',') echo "tags=[$output]" >> $GITHUB_OUTPUT @@ -96,7 +96,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: script: | - const commands = ${{ steps.snapshot.outputs.tags }}.map(tag => '```sh\n' + `pnpm add ${tag}` + '\n```') + const commands = ${{ steps.snapshot.outputs.tags }}.map(tag => '```sh\n' + `nix develop --command -- pnpm add ${tag}` + '\n```') const header = `**Good news @${{ github.actor }}, your snapshot has been published!**` const footer = `You can review the build log [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).` @@ -117,5 +117,5 @@ jobs: edit-mode: replace body: | **Sorry @${{ github.actor }}, I failed to publish the snapshot!** - + You can review the build log [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}). diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ad43ce6..35301af 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,13 +15,10 @@ jobs: test: name: Test runs-on: ubuntu-latest - strategy: - fail-fast: false - steps: - uses: actions/checkout@v3 - name: Install dependencies uses: ./.github/actions/setup with: cachixAuthToken: ${{ secrets.CACHIX_AUTH_TOKEN }} - - run: pnpm vitest + - run: nix develop --command -- pnpm vitest