From bb35630c59dd5a5fab7f749ca2e0e35253de8502 Mon Sep 17 00:00:00 2001 From: Aiden Park <97845814+adnpark@users.noreply.github.com> Date: Tue, 16 Jan 2024 16:55:48 +0900 Subject: [PATCH] Improve CI with workflows (#7) * ci: improve ci * fix: fix action directory * chore: format --------- Co-authored-by: adnpark --- .changeset/README.md | 8 +++ .changeset/config.json | 11 ++++ .../actions/install-dependencies/action.yml | 12 ++++ .github/workflows/build.yml | 19 ------ .github/workflows/on-pull-request.yml | 32 ++++++++++ .github/workflows/on-push-to-main.yml | 60 +++++++++++++++++++ .github/workflows/verify.yml | 44 ++++++++++++++ package.json | 7 ++- 8 files changed, 172 insertions(+), 21 deletions(-) create mode 100644 .changeset/README.md create mode 100644 .changeset/config.json create mode 100644 .github/actions/install-dependencies/action.yml delete mode 100644 .github/workflows/build.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/.changeset/README.md b/.changeset/README.md new file mode 100644 index 0000000..e5b6d8d --- /dev/null +++ b/.changeset/README.md @@ -0,0 +1,8 @@ +# Changesets + +Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works +with multi-package repos, or single-package repos to help you version and publish your code. You can +find the full documentation for it [in our repository](https://github.com/changesets/changesets) + +We have a quick list of common questions to get you started engaging with this project in +[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) diff --git a/.changeset/config.json b/.changeset/config.json new file mode 100644 index 0000000..fce1c26 --- /dev/null +++ b/.changeset/config.json @@ -0,0 +1,11 @@ +{ + "$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json", + "changelog": "@changesets/cli/changelog", + "commit": false, + "fixed": [], + "linked": [], + "access": "public", + "baseBranch": "main", + "updateInternalDependencies": "patch", + "ignore": [] +} diff --git a/.github/actions/install-dependencies/action.yml b/.github/actions/install-dependencies/action.yml new file mode 100644 index 0000000..9dd9fb4 --- /dev/null +++ b/.github/actions/install-dependencies/action.yml @@ -0,0 +1,12 @@ +name: "Install dependencies" +description: "Prepare repository and all dependencies" + +runs: + using: "composite" + steps: + - name: Set up Bun + uses: oven-sh/setup-bun@v1 + + - name: Install dependencies + shell: bash + run: bun install --ignore-scripts \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 96889e4..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: build -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - build: - name: build - runs-on: ubuntu-latest - steps: - # ... - - uses: actions/checkout@v3 - - uses: oven-sh/setup-bun@v1 - - # run any `bun` or `bunx` command - - run: bun install - - run: bun run build diff --git a/.github/workflows/on-pull-request.yml b/.github/workflows/on-pull-request.yml new file mode 100644 index 0000000..b6ec924 --- /dev/null +++ b/.github/workflows/on-pull-request.yml @@ -0,0 +1,32 @@ +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 + + size: + name: Size + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - name: Clone repository + uses: actions/checkout@v3 + + - name: Install dependencies + uses: ./.github/actions/install-dependencies + + - name: Report bundle size + uses: andresz1/size-limit-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + package_manager: bun diff --git a/.github/workflows/on-push-to-main.yml b/.github/workflows/on-push-to-main.yml new file mode 100644 index 0000000..6ebede1 --- /dev/null +++ b/.github/workflows/on-push-to-main.yml @@ -0,0 +1,60 @@ +name: Main +on: + push: + branches: [main] + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + verify: + name: Verify + uses: ./.github/workflows/verify.yml + secrets: inherit + + changesets: + name: Changesets + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - name: Clone repository + uses: actions/checkout@v3 + 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 + uses: changesets/action@v1 + with: + version: bun run changeset:version + commit: 'chore: version package' + title: 'chore: version package' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + release: + name: Release + needs: verify + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - name: Clone repository + uses: actions/checkout@v3 + + - name: Install dependencies + uses: ./.github/actions/install-dependencies + + - name: Publish to NPM + uses: changesets/action@v1 + with: + publish: bun run changeset:release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml new file mode 100644 index 0000000..c282ef1 --- /dev/null +++ b/.github/workflows/verify.yml @@ -0,0 +1,44 @@ +name: Verify +on: + workflow_call: + workflow_dispatch: + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - name: Clone repository + uses: actions/checkout@v3 + + - name: Install dependencies + uses: ./.github/actions/install-dependencies + + - name: Lint code + run: bun format && bun lint:fix + + - uses: stefanzweifel/git-auto-commit-action@v4 + 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' + + build: + name: Build + needs: lint + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - name: Clone repository + uses: actions/checkout@v3 + + - name: Install dependencies + uses: ./.github/actions/install-dependencies + + - name: Build + run: bun run build \ No newline at end of file diff --git a/package.json b/package.json index b27aaf1..ebd9319 100644 --- a/package.json +++ b/package.json @@ -6,11 +6,14 @@ "type": "module", "scripts": { "build": "tsc", - "start": "node dist/index.js", + "changeset": "changeset", + "changeset:release": "bun run build && changeset publish", + "changeset:version": "changeset version && bun install --lockfile-only", "dev": "ts-node src/index.ts", "format": "biome format ./src --write", "lint": "biome check ./src", - "lint:fix": "bun run lint --apply" + "lint:fix": "bun run lint --apply", + "start": "node dist/index.js" }, "bin": { "zerodev": "./dist/index.js"