From 83dbb0127faafad8ade59bcc9b2d0ee751edbd79 Mon Sep 17 00:00:00 2001 From: Mrugesh Mohapatra Date: Tue, 2 Apr 2024 11:13:44 +0530 Subject: [PATCH] feat: publish from GitHub Actions --- .github/workflows/publish.yml | 113 +++++++++++++++++++ .github/workflows/{build.yml => re-lint.yml} | 29 ++--- .npmrc | 2 + .nvmrc | 1 + 4 files changed, 126 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/publish.yml rename .github/workflows/{build.yml => re-lint.yml} (78%) create mode 100644 .npmrc create mode 100644 .nvmrc diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..18f10bb7 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,113 @@ +name: Publish + +on: + push: + branches: + - main + - live + pull_request: + types: [opened, synchronize, reopened] + workflow_dispatch: + +jobs: + lint: + name: Lint + uses: ./.github/workflows/re-lint.yml + + # test: + + build: + name: Build + runs-on: ubuntu-latest + # needs: test + + env: + CI: true + + strategy: + matrix: + node-version: [20.x] + + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4 + with: + node-version: ${{ matrix.node-version }} + + - name: Install pnpm + uses: pnpm/action-setup@v2 + id: pnpm-install + with: + version: 8 + run_install: false + + - name: Get pnpm store directory + id: pnpm-cache + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT + + - name: Cache + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4 + with: + path: | + ${{ steps.pnpm-cache.outputs.STORE_PATH }} + key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} + + - name: Install dependencies + run: | + pnpm install --frozen-lockfile + + - name: Build + run: | + pnpm build + + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: site + path: dist + + deploy: + if: github.event_name == 'pull_request' + name: Deploy + runs-on: ubuntu-latest + needs: build + environment: + name: cloudflare-pages + + steps: + - name: Download Artifact + uses: actions/download-artifact@v4 + with: + name: site + path: dist + + - name: Publish to Cloudflare Pages + id: cloudflare-pages + uses: cloudflare/pages-action@v1 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + projectName: ${{ secrets.CLOUDFLARE_PROJECT_NAME }} + directory: dist + gitHubToken: ${{ secrets.GITHUB_TOKEN }} + # Optional: Change the Wrangler version + wranglerVersion: '3' + + - name: Notify + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: 'Deployed to Cloudflare Pages. Preview: https://${{ steps.cloudflare-pages.outputs.url }}' + }) diff --git a/.github/workflows/build.yml b/.github/workflows/re-lint.yml similarity index 78% rename from .github/workflows/build.yml rename to .github/workflows/re-lint.yml index 8f0039be..641c66f1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/re-lint.yml @@ -1,21 +1,12 @@ -name: Build Check +# This is a reusable workflow that can be called from other workflows +name: Lint -on: - push: - branches: - - main - - live - pull_request: - types: [opened, synchronize, reopened] - workflow_dispatch: +on: [workflow_call] jobs: - # lint: - # test: - build: - name: Build + lint: + name: Lint runs-on: ubuntu-latest - # needs: test env: CI: true @@ -36,9 +27,6 @@ jobs: - name: Install pnpm uses: pnpm/action-setup@v2 id: pnpm-install - with: - version: 8 - run_install: false - name: Get pnpm store directory id: pnpm-cache @@ -59,6 +47,9 @@ jobs: run: | pnpm install --frozen-lockfile - - name: Build + - name: Install dependencies and lint run: | - pnpm build + pnpm install + pnpm lint + env: + CI: true diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000..618365b2 --- /dev/null +++ b/.npmrc @@ -0,0 +1,2 @@ +engine-strict=true +enable-pre-post-scripts=true diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 00000000..2b9cabc0 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +20.12.0