From 5437a33752dd26e675a1928ebcaa9eabbc2de634 Mon Sep 17 00:00:00 2001 From: ocavue Date: Thu, 22 Aug 2024 18:17:55 +1000 Subject: [PATCH] ci: add release workflow (#14) Release-As: 0.0.8 --- .github/actions/setup/action.yml | 31 ++++++++++++++++++++++++++++++ .github/workflows/chromatic.yaml | 14 +++----------- .github/workflows/release.yaml | 33 ++++++++++++++++++++++++++++++++ .github/workflows/test.yaml | 31 +++--------------------------- 4 files changed, 70 insertions(+), 39 deletions(-) create mode 100644 .github/actions/setup/action.yml create mode 100644 .github/workflows/release.yaml diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml new file mode 100644 index 0000000..27862d9 --- /dev/null +++ b/.github/actions/setup/action.yml @@ -0,0 +1,31 @@ +name: Setup +description: Shared setup for all actions + +inputs: + node-version: + description: The version of node.js + required: false + default: "20" + +runs: + using: composite + steps: + - name: Install pnpm + uses: pnpm/action-setup@v4 + with: + version: 8 + + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node-version }} + cache: pnpm + registry-url: "https://npm.pkg.github.com" + + - name: Install dependencies + run: pnpm install + shell: bash + + - name: Build + run: pnpm build + shell: bash diff --git a/.github/workflows/chromatic.yaml b/.github/workflows/chromatic.yaml index c3f6679..027bedb 100644 --- a/.github/workflows/chromatic.yaml +++ b/.github/workflows/chromatic.yaml @@ -9,18 +9,10 @@ jobs: name: Run Chromatic runs-on: ubuntu-latest steps: - - name: Checkout code + - name: Checkout uses: actions/checkout@v4 - with: - fetch-depth: 0 - - uses: actions/setup-node@v4 - with: - node-version: 20 - - uses: pnpm/action-setup@v4 - with: - version: 8 - - name: Install dependencies - run: pnpm install + - name: Setup environment + uses: ./.github/actions/setup - name: Build run: pnpm build - name: Run Chromatic diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..d77fa52 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,33 @@ +name: Release + +on: + push: + branches: + - main + +jobs: + version: + runs-on: ubuntu-latest + steps: + - uses: googleapis/release-please-action@v4 + id: release-please + with: + release-type: node + outputs: + release_created: ${{ steps.release-please.outputs.release_created }} + + publish: + runs-on: ubuntu-latest + needs: [version] + if: ${{ needs.version.outputs.release_created }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup environment + uses: ./.github/actions/setup + - name: Build + run: pnpm build + - name: Publish to NPM + run: pnpm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0d7e7a5..ef74acc 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -14,37 +14,12 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - - name: Install Node.js - uses: actions/setup-node@v4 - with: - node-version: 20 - - - uses: pnpm/action-setup@v3 - name: Install pnpm - with: - version: 8 - run_install: false - - - name: Get pnpm store directory - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - - - uses: actions/cache@v4 - name: Setup pnpm cache - with: - path: ${{ env.STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - - name: Install dependencies - run: pnpm install + - name: Setup environment + uses: ./.github/actions/setup - name: Lint run: pnpm run lint - name: Test run: pnpm run coverage - - name: 'Report Coverage' + - name: "Report Coverage" if: always() uses: davelosert/vitest-coverage-report-action@v2