From e89aa0c774015b5d19403d888df8f27a08b2ebd0 Mon Sep 17 00:00:00 2001 From: Sawa <34698182+sawaYch@users.noreply.github.com> Date: Thu, 4 Apr 2024 15:22:22 +0800 Subject: [PATCH] fix(ci): update release & publish script --- .github/workflows/publish-source-code.yml | 56 ----------------------- .github/workflows/release.yml | 45 +++++++++--------- package.json | 4 +- turbo.json | 6 +++ 4 files changed, 33 insertions(+), 78 deletions(-) delete mode 100644 .github/workflows/publish-source-code.yml diff --git a/.github/workflows/publish-source-code.yml b/.github/workflows/publish-source-code.yml deleted file mode 100644 index 33ebfab..0000000 --- a/.github/workflows/publish-source-code.yml +++ /dev/null @@ -1,56 +0,0 @@ -on: - push: - tags: - - 'v*' - workflow_dispatch: {} - -name: Publish -jobs: - publish: - runs-on: ubuntu-latest - steps: - - name: Checkout Repo - uses: actions/checkout@v4 - with: - fetch-depth: 2 - - - name: Use Node.js 20 - uses: actions/setup-node@v4 - with: - node-version: 20 - registry-url: https://registry.npmjs.org/ - - - name: Restore project deps - run: npm ci - - - name: Build the package next-youtube-livechat - run: cd packages/next-youtube-livechat && npm run build - - - name: Lint check - run: npm run lint - - - name: Code format check - run: npm run format - - - name: Typescript check - run: npm run typecheck - - - run: cd packages/next-youtube-livechat && npm publish - env: - NPM_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }} - NODE_ENV: 'production' - - github-release: - needs: publish - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: 20 - registry-url: https://registry.npmjs.org/ - - run: npm i -g github-release-from-changelog - - run: github-release-from-changelog - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NODE_ENV: 'production' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8f1382d..ffa1ef0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,10 +1,12 @@ -name: Release +# trigger only when packages code modified are merged on main branch +name: Bump version & publish to NPM on: push: - branches: [master] - # paths: - # - 'packages/next-youtube-livechat/**' + branches: + - main + paths: + - 'packages/next-youtube-livechat/**' workflow_dispatch: {} jobs: @@ -12,16 +14,13 @@ jobs: name: Release if: ${{ github.repository_owner == 'sawaYch' }} runs-on: ubuntu-latest - # permissions: - # contents: write - # deployments: write - # packages: write - # pull-requests: write + permissions: + contents: write # to create release (changesets/action) + issues: write # to post issue comments (changesets/action) + pull-requests: write # to create pull request (changesets/action) steps: - name: Checkout uses: actions/checkout@v4 - with: - fetch-depth: 2 - name: Setup Node.js 20 uses: actions/setup-node@v4 @@ -31,26 +30,30 @@ jobs: - name: Restore dependencies run: npx ci - - name: Install semantic-release extra plugins - run: npm install --save-dev @semantic-release/changelog @semantic-release/git - - - name: Restore project deps - run: npm ci - - name: Build the package next-youtube-livechat - run: cd packages/next-youtube-livechat && npm run build + run: npm run build + working-directory: packages/next-youtube-livechat - name: Lint check run: npm run lint + working-directory: packages/next-youtube-livechat - name: Code format check run: npm run format + working-directory: packages/next-youtube-livechat - name: Typescript check run: npm run typecheck + working-directory: packages/next-youtube-livechat - - name: Release + - name: Create Release Pull Request or Publish to npm + uses: changesets/action@v1 + with: + publish: npm run release + version: npm run version + commit: 'chore: new release' + title: 'chore: new release candidate' + createGithubReleases: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }} - run: npx semantic-release + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/package.json b/package.json index 2cb5bb7..a1bd11c 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,9 @@ "lint": "turbo run lint", "format": "turbo run format", "format:fix": "turbo run format:fix", - "typecheck": "turbo run typecheck" + "typecheck": "turbo run typecheck", + "version": "npx changeset version", + "release": "npx changeset publish" }, "devDependencies": { "@changesets/changelog-github": "^0.5.0", diff --git a/turbo.json b/turbo.json index 54c5b0e..c6ea844 100644 --- a/turbo.json +++ b/turbo.json @@ -23,6 +23,12 @@ }, "dev": { "cache": false + }, + "release": { + "cache": false + }, + "version": { + "cache": false } } }