Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
Improve CI with Nix (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
IMax153 authored Dec 2, 2023
1 parent 3bb0842 commit 5c24ea4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 41 deletions.
24 changes: 5 additions & 19 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
8 changes: 6 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 }}).`
Expand All @@ -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 }}).
5 changes: 1 addition & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5c24ea4

Please sign in to comment.