From 3c63d20b0d02f0732c1caed0270e46428a30a79b Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Sat, 23 Sep 2023 21:57:54 +0900 Subject: [PATCH] add github action workflow --- .github/workflows/ci.yml | 130 ++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 63 ++++++++++++++++ 2 files changed, 193 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6aa8cfd --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,130 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + lint: + name: Lint + strategy: + matrix: + os: [ubuntu-latest] + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout codes + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Lint codes + run: bun run lint + + build: + name: Build + strategy: + matrix: + os: [ubuntu-latest] + node: [18.x] + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout codes + uses: actions/checkout@v4 + + - name: Setup bun + uses: oven-sh/setup-bun@v1 + + - name: Enable corepack + run: corepack enable + + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node }} + + - name: Install dependencies + run: bun install + + - name: Build codes + run: bun run build + + test: + name: Test + strategy: + matrix: + os: [ubuntu-latest] + node: [18.x] + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout codes + uses: actions/checkout@v4 + + - name: Setup bun + uses: oven-sh/setup-bun@v1 + + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node }} + + - name: Enable corepack + run: corepack enable + + - name: Install dependencies + run: bun install + + - name: Build codes + run: bun run test + + edge-release: + name: Edge Release + needs: + - lint + - build + - test + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + node: [18] + steps: + - name: Checkout codes + uses: actions/checkout@v4 + + - name: Setup bun + uses: oven-sh/setup-bun@v1 + + - uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node }} + + - name: Enable corepack + run: corepack enable + + - name: Install dependencies + run: bun install + + - name: Build + run: bun run build + + - name: Release Edge + if: | + github.event_name == 'push' && + !startsWith(github.event.head_commit.message, '[skip-release]') && + !startsWith(github.event.head_commit.message, 'chore') && + !startsWith(github.event.head_commit.message, 'release') && + !startsWith(github.event.head_commit.message, 'docs') + run: ./scripts/release.sh + env: + NPM_TOKEN: ${{secrets.NPM_ORG_TOKEN}} + EDGE_RELEASE: 'true' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..bc335eb --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,63 @@ +name: Release + +on: + push: + branches-ignore: + - '**' + tags: + - 'v*' + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: Checkout codes + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + + - name: Setup bun + uses: oven-sh/setup-bun@v1 + + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: 18 + + - name: Enable corepack + run: corepack enable + + - name: Extract version tag + if: startsWith( github.ref, 'refs/tags/v' ) + uses: jungwinter/split@v2 + id: split + with: + msg: ${{ github.ref }} + separator: '/' + + - name: Create Github Release + run: gh release create ${{ steps.split.outputs._2 }} --generate-notes + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Generate changelog + run: | + git restore --source=HEAD --staged --worktree -- package.json bun.lockb + bun install + bun run build + bun run changelog -- --tag=${{ steps.split.outputs._2 }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Commit changelog + uses: stefanzweifel/git-auto-commit-action@v4 + with: + branch: main + file_pattern: '*.md' + commit_message: 'chore: sync changelog' + + - name: Publish package + run: ./scripts/release.sh + env: + NPM_TOKEN: ${{secrets.NPM_ORG_TOKEN}}