From dc53a568ef2813621972226aa8243e49056b0825 Mon Sep 17 00:00:00 2001 From: hotwater Date: Wed, 5 Jun 2024 14:28:54 +0300 Subject: [PATCH] ci: add release workflows --- .../actions/install-dependencies/action.yml | 22 ++++ .github/workflows/ci.yml | 116 ------------------ .github/workflows/label_issues.yml | 21 ---- .github/workflows/on-pull-request.yml | 14 +++ .github/workflows/on-push-to-main.yml | 62 ++++++++++ .github/workflows/verify.yml | 63 ++++++++++ package.json | 1 - 7 files changed, 161 insertions(+), 138 deletions(-) create mode 100644 .github/actions/install-dependencies/action.yml delete mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/label_issues.yml create mode 100644 .github/workflows/on-pull-request.yml create mode 100644 .github/workflows/on-push-to-main.yml create mode 100644 .github/workflows/verify.yml diff --git a/.github/actions/install-dependencies/action.yml b/.github/actions/install-dependencies/action.yml new file mode 100644 index 0000000..d9d0f52 --- /dev/null +++ b/.github/actions/install-dependencies/action.yml @@ -0,0 +1,22 @@ +name: "Install dependencies" +description: "Prepare repository and all dependencies" + +runs: + using: "composite" + steps: + - name: Set up pnpm + uses: pnpm/action-setup@v4 + + - name: Set up Node + uses: actions/setup-node@v3 + with: + cache: pnpm + node-version: 20 + + - uses: oven-sh/setup-bun@v1 + with: + bun-version: latest + + - name: Install dependencies + shell: bash + run: pnpm install diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index fea9d5e..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,116 +0,0 @@ -name: CI -on: - # CI is run on main because new branches can only access caches from master, not previous branches. - # So building on master allows new PR's to get the cache from before. - push: - branches: [main] - pull_request: - branches: [main] - -# prevent multiple simultaneous test runs -concurrency: - group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}" - cancel-in-progress: true - -jobs: - analyze: - timeout-minutes: 10 - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [20] - pnpm-version: [8.6.2] - - steps: - - uses: actions/checkout@v3 - - - uses: pnpm/action-setup@v2.2.4 - with: - version: ${{ matrix.pnpm-version }} - - - name: Set up Node ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - cache: 'pnpm' - node-version: ${{ matrix.node-version }} - env: - # https://github.com/actions/setup-node/issues/772 - FORCE_COLOR: 0 - - - name: Cache pnpm - uses: actions/cache@v3 - with: - path: ~/.pnpm-store - key: ${{ runner.os }}--node--${{ hashFiles('pnpm-lock.yaml') }} - restore-keys: pnpm- - - - name: Install dependencies - run: pnpm install - - - name: Run build - run: pnpm build - - - name: Run linter - run: pnpm lint:ci - - test: - timeout-minutes: 10 - runs-on: "ubuntu-latest" - - strategy: - matrix: - pnpm-version: [8.6.2] - node-version: [18, 20] - - steps: - - uses: actions/checkout@v3 - - - uses: pnpm/action-setup@v2.2.4 - with: - version: ${{ matrix.pnpm-version }} - - - name: Set up Node ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - cache: 'pnpm' - node-version: ${{ matrix.node-version }} - env: - # https://github.com/actions/setup-node/issues/772 - FORCE_COLOR: 0 - - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - cache: 'pnpm' - env: - # https://github.com/actions/setup-node/issues/772 - FORCE_COLOR: 0 - - - name: Restore cached dependencies for Node modules. - id: module-cache - uses: actions/cache@v3 - with: - path: ${{ github.workspace }}/node_modules - key: ${{ runner.os }}--node--${{ matrix.node-version}}--${{ hashFiles('**/pnpm-lock.yaml') }} - - - name: Install dependencies - run: pnpm install - - - name: Run build - run: pnpm build - - - name: Log in to Docker Hub to avoid rate limiting - uses: docker/login-action@v2 - with: - username: ${{ secrets.FARCASTERXYZ_DOCKER_HUB_USER }} - password: ${{ secrets.FARCASTERXYZ_DOCKER_HUB_TOKEN }} - - - name: Start background services - shell: bash - run: docker compose -f ./apps/relay/docker-compose.yml up --build --detach redis - - - name: Run tests - run: pnpm test:ci - - - name: Upload coverage results - uses: codecov/codecov-action@v3 diff --git a/.github/workflows/label_issues.yml b/.github/workflows/label_issues.yml deleted file mode 100644 index ff719e2..0000000 --- a/.github/workflows/label_issues.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Label Issues - -on: - issues: - types: [opened] - -jobs: - label_issues: - runs-on: ubuntu-latest - steps: - - name: Add label - uses: actions/github-script@v6 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - github.rest.issues.addLabels({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - labels: ['s-triage'] - }) diff --git a/.github/workflows/on-pull-request.yml b/.github/workflows/on-pull-request.yml new file mode 100644 index 0000000..16e99f8 --- /dev/null +++ b/.github/workflows/on-pull-request.yml @@ -0,0 +1,14 @@ +name: Pull request +on: + pull_request: + types: [opened, reopened, synchronize, ready_for_review] + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + verify: + name: Verify + uses: ./.github/workflows/verify.yml + secrets: inherit diff --git a/.github/workflows/on-push-to-main.yml b/.github/workflows/on-push-to-main.yml new file mode 100644 index 0000000..610101c --- /dev/null +++ b/.github/workflows/on-push-to-main.yml @@ -0,0 +1,62 @@ +name: Main +on: + push: + branches: [main] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + verify: + name: Verify + uses: ./.github/workflows/verify.yml + secrets: inherit + + changesets: + name: Changesets + needs: verify + permissions: + contents: write + id-token: write + issues: write + repository-projects: write + deployments: write + packages: write + pull-requests: write + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - name: Clone repository + uses: actions/checkout@v4 + with: + # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits + fetch-depth: 0 + + - name: Install dependencies + uses: ./.github/actions/install-dependencies + + - name: Create version pull request or publish to npm + uses: changesets/action@v1 + with: + title: 'chore: version packages' + commit: 'chore: version packages' + publish: pnpm changeset:release + version: pnpm changeset:version + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Publish Prerelease + if: steps.changesets.outputs.published != 'true' + continue-on-error: true + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + npm config set "//registry.npmjs.org/:_authToken" "$NPM_TOKEN" + git reset --hard origin/main + pnpm clean + pnpm changeset version --no-git-tag --snapshot canary + pnpm changeset publish --no-git-tag --snapshot canary --tag canary diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml new file mode 100644 index 0000000..2cee831 --- /dev/null +++ b/.github/workflows/verify.yml @@ -0,0 +1,63 @@ +name: Verify +on: + workflow_call: + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - name: Clone repository + uses: actions/checkout@v4 + + - name: Install dependencies + uses: ./.github/actions/install-dependencies + + - name: Lint code + run: pnpm format && pnpm lint + + - uses: stefanzweifel/git-auto-commit-action@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + commit_message: 'chore: format' + commit_user_name: 'github-actions[bot]' + commit_user_email: 'github-actions[bot]@users.noreply.github.com' + + types: + name: Types + runs-on: ubuntu-latest + + steps: + - name: Clone repository + uses: actions/checkout@v4 + + - name: Install dependencies + uses: ./.github/actions/install-dependencies + + - name: Build + run: pnpm build + + - name: Check types + run: pnpm typecheck + + test: + name: Test + runs-on: ubuntu-latest + steps: + - name: Clone repository + uses: actions/checkout@v4 + + - name: Install dependencies + uses: ./.github/actions/install-dependencies + - run: pnpm preconstruct + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 'latest' + + - name: Run tests + run: pnpm test diff --git a/package.json b/package.json index 962c2f9..71ddc45 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,5 @@ { "description": "A monorepo for Farcaster Auth", - "version": "0.0.0", "private": true, "packageManager": "pnpm@8.10.5", "scripts": {