From a2d92657cfe2debcf5abcd9462eb63a44cf8c7e4 Mon Sep 17 00:00:00 2001 From: Maxence Raballand Date: Thu, 2 May 2024 10:49:35 +0200 Subject: [PATCH 1/3] update CI --- .../{action.yaml => action.yml} | 0 .github/workflows/changesets.yml | 69 +++++++++++++++++++ .github/workflows/{tests.yaml => tests.yml} | 0 .github/workflows/verify.yml | 67 ++++++++++++++++++ package.json | 4 ++ scripts/prepublishOnly.ts | 10 +++ 6 files changed, 150 insertions(+) rename .github/actions/install-dependencies/{action.yaml => action.yml} (100%) create mode 100644 .github/workflows/changesets.yml rename .github/workflows/{tests.yaml => tests.yml} (100%) create mode 100644 .github/workflows/verify.yml create mode 100644 scripts/prepublishOnly.ts diff --git a/.github/actions/install-dependencies/action.yaml b/.github/actions/install-dependencies/action.yml similarity index 100% rename from .github/actions/install-dependencies/action.yaml rename to .github/actions/install-dependencies/action.yml diff --git a/.github/workflows/changesets.yml b/.github/workflows/changesets.yml new file mode 100644 index 0000000..ea6fe34 --- /dev/null +++ b/.github/workflows/changesets.yml @@ -0,0 +1,69 @@ +name: Changesets +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: Create version pull request + 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 + submodules: 'recursive' + + - name: Install dependencies + uses: ./.github/actions/install-dependencies + + - name: Create Version Pull Request + uses: changesets/action@v1 + with: + commit: 'chore: version package' + title: 'chore: version package' + version: bun run changeset:version + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + release: + name: Release + needs: verify + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + contents: write + id-token: write + + steps: + - name: Clone repository + uses: actions/checkout@v4 + with: + submodules: 'recursive' + + - name: Install dependencies + uses: ./.github/actions/install-dependencies + + - name: Publish to NPM + uses: changesets/action@v1 + with: + createGithubReleases: ${{ github.ref == 'refs/heads/main' }} + publish: bun run changeset:publish + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + # https://docs.npmjs.com/generating-provenance-statements + NPM_CONFIG_PROVENANCE: true \ No newline at end of file diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yml similarity index 100% rename from .github/workflows/tests.yaml rename to .github/workflows/tests.yml diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml new file mode 100644 index 0000000..e0c7b49 --- /dev/null +++ b/.github/workflows/verify.yml @@ -0,0 +1,67 @@ +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@v4 + with: + submodules: 'recursive' + + - name: Install dependencies + uses: ./.github/actions/install-dependencies + + - name: Lint code + run: bun format && bun lint:fix + + - 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' + + build: + name: Build + needs: lint + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - name: Clone repository + uses: actions/checkout@v4 + with: + submodules: 'recursive' + + - name: Install dependencies + uses: ./.github/actions/install-dependencies + + - name: Build + run: bun run build + + tests: + name: Test + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - name: Clone repository + uses: actions/checkout@v4 + with: + submodules: 'recursive' + + - name: Install dependencies + uses: ./.github/actions/install-dependencies + + - name: Run tests + run: bun run test:ci + + \ No newline at end of file diff --git a/package.json b/package.json index a4e679b..1f40b24 100644 --- a/package.json +++ b/package.json @@ -9,10 +9,14 @@ "build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./src/_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./src/_cjs/package.json", "build:esm": "tsc --project ./tsconfig.build.json --module es2015 --outDir ./src/_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./src/_esm/package.json", "build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./src/_types --emitDeclarationOnly --declaration --declarationMap", + "changeset": "changeset", + "changeset:publish": "bun run prepublishOnly && bun run build && changeset publish", + "changeset:version": "changeset version", "clean": "rimraf src/_esm src/_cjs src/_types", "format": "biome format . --write", "lint": "biome check .", "lint:fix": "bun run lint --apply", + "prepublishOnly": "bun scripts/prepublishOnly.ts", "test": "vitest -c ./test/vitest.config.ts dev", "test:ci": "CI=true vitest -c ./test/vitest.config.ts --coverage --retry=3 --bail=1 --pool=forks" }, diff --git a/scripts/prepublishOnly.ts b/scripts/prepublishOnly.ts new file mode 100644 index 0000000..00d0954 --- /dev/null +++ b/scripts/prepublishOnly.ts @@ -0,0 +1,10 @@ +import { join } from 'node:path' + +const packageJsonPath = join(import.meta.dir, '../src/package.json') +const packageJson = await Bun.file(packageJsonPath).json() + +// NOTE: We explicitly don't want to publish the type field. +// We create a separate package.json for `dist/cjs` and `dist/esm` that has the type field. +delete packageJson.type + +Bun.write(packageJsonPath, JSON.stringify(packageJson, null, 2)) \ No newline at end of file From 724a97733f90ee31968b90e5a1cecfb59e6347fa Mon Sep 17 00:00:00 2001 From: Maxence Raballand Date: Thu, 2 May 2024 10:49:55 +0200 Subject: [PATCH 2/3] . --- scripts/prepublishOnly.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/prepublishOnly.ts b/scripts/prepublishOnly.ts index 00d0954..d1ab1a1 100644 --- a/scripts/prepublishOnly.ts +++ b/scripts/prepublishOnly.ts @@ -7,4 +7,4 @@ const packageJson = await Bun.file(packageJsonPath).json() // We create a separate package.json for `dist/cjs` and `dist/esm` that has the type field. delete packageJson.type -Bun.write(packageJsonPath, JSON.stringify(packageJson, null, 2)) \ No newline at end of file +Bun.write(packageJsonPath, JSON.stringify(packageJson, null, 2)) From 7d9509d93946813132128c2380ed7288f0ee5907 Mon Sep 17 00:00:00 2001 From: Maxence Raballand Date: Thu, 2 May 2024 10:52:31 +0200 Subject: [PATCH 3/3] Adding changeset --- .changeset/slow-wasps-notice.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/slow-wasps-notice.md diff --git a/.changeset/slow-wasps-notice.md b/.changeset/slow-wasps-notice.md new file mode 100644 index 0000000..2aa64b2 --- /dev/null +++ b/.changeset/slow-wasps-notice.md @@ -0,0 +1,5 @@ +--- +"@mangrovedao/mgv": patch +--- + +Adding CI pipeline