From 69962121e4949ed5bbad5d5cae1d19a0582a62ee Mon Sep 17 00:00:00 2001 From: jiaojiaojiaoCpbr Date: Wed, 21 Feb 2024 13:02:20 +0800 Subject: [PATCH] ci: add github action for publish npm package --- .github/workflows/gerald-pr.yml | 13 ---- .github/workflows/node-ci-main.yml | 80 ----------------------- .github/workflows/npm-publish.yaml | 26 ++++++++ .github/workflows/release.yml | 101 ----------------------------- 4 files changed, 26 insertions(+), 194 deletions(-) delete mode 100644 .github/workflows/gerald-pr.yml delete mode 100644 .github/workflows/node-ci-main.yml create mode 100644 .github/workflows/npm-publish.yaml delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/gerald-pr.yml b/.github/workflows/gerald-pr.yml deleted file mode 100644 index e701b32c89..0000000000 --- a/.github/workflows/gerald-pr.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Gerald - Notify and Request Reviewers On Pull Request -"on": - pull_request: - types: [opened, synchronize, reopened, ready_for_review, edited] - -jobs: - gerald: - runs-on: ubuntu-latest - steps: - - uses: Khan/actions@gerald-pr-v0 - with: - token: ${{ secrets.GITHUB_TOKEN }} - admin-token: ${{ secrets.KHAN_ACTIONS_BOT_TOKEN }} diff --git a/.github/workflows/node-ci-main.yml b/.github/workflows/node-ci-main.yml deleted file mode 100644 index 7c3e531fd4..0000000000 --- a/.github/workflows/node-ci-main.yml +++ /dev/null @@ -1,80 +0,0 @@ -name: Node CI (landed on protected branch) - -on: - push: - branches: - - main - - changeset-release/* - - feature/* - -# Our jobs run like this to minimize wasting resource cycles: -# 1. Prime caches for primary configuration. This way subsequent jobs -# can run in parallel but rely on this primed cache. -# 2. Coverage -# -# For pushes directly to a branch, we assume a PR has been used with wider -# checks, this just makes sure our coverage data is up-to-date. -jobs: - prime_cache_primary: - name: Prime node_modules cache for primary configuration - runs-on: ${{ matrix.os }} - strategy: - # Use a matrix as it means we get the version info in the job name - # which is very helpful. - matrix: - os: [ubuntu-latest] - node-version: [20.x] - steps: - - uses: actions/checkout@v4 - - name: Install & cache node_modules - uses: ./.github/actions/shared-node-cache - with: - node-version: ${{ matrix.node-version }} - ssh-private-key: ${{ secrets.KHAN_ACTIONS_BOT_SSH_PRIVATE_KEY }} - - coverage: - needs: [prime_cache_primary] - name: Jest Coverage - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest] - node-version: [20.x] - steps: - - uses: actions/checkout@v4 - - - name: Install & cache node_modules - uses: ./.github/actions/shared-node-cache - with: - node-version: ${{ matrix.node-version }} - ssh-private-key: ${{ secrets.KHAN_ACTIONS_BOT_SSH_PRIVATE_KEY }} - - - name: Jest with coverage - run: yarn coverage - - - name: Upload Coverage - uses: codecov/codecov-action@v3 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: ./coverage/coverage-final.json - - cypress: - needs: [prime_cache_primary] - name: Cypress - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest] - node-version: [20.x] - steps: - - name: Checking out latest commit - uses: actions/checkout@v4 - - - name: Install & cache node_modules - uses: ./.github/actions/shared-node-cache - with: - node-version: ${{ matrix.node-version }} - ssh-private-key: ${{ secrets.KHAN_ACTIONS_BOT_SSH_PRIVATE_KEY }} - - - name: Run test with coverage - run: yarn cypress:ci diff --git a/.github/workflows/npm-publish.yaml b/.github/workflows/npm-publish.yaml new file mode 100644 index 0000000000..98274808cf --- /dev/null +++ b/.github/workflows/npm-publish.yaml @@ -0,0 +1,26 @@ +name: 🔧 Publish to npm + +on: workflow_dispatch + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: "20.10.0" + cache: "yarn" + registry-url: https://registry.npmjs.org + scope: "@junyiacademy" + - name: Install dependencies + run: yarn --frozen-lockfile + - name: Build perseus-core + run: npm run build:publish + working-directory: ./packages + - name: Publish to npm + run: npm publish + working-directory: ./packages + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 9f0880bc19..0000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,101 +0,0 @@ -name: Release - -on: - push: - branches: - - main - -concurrency: ${{ github.workflow }}-${{ github.ref }} - -# This workflow will run changesets depending on two different scenarios: -# -# 1. If we are landing a specific commit into main (Author PR), then -# changesets will check if there are changes verifying the Markdown files -# generated automatically: -# -# a) There are new versions and there's NO Release PR, then the changesets -# action will create a new Release PR. -# -# b) There's a Release PR, then the changesets action will update the -# existing Release PR with the new commit. -# -# NOTE: (in both cases, changesets will modify the new version in -# package.json for each package, and will remove the MD files as part of the -# Release PR). -# -# 2. If we are landing the Release PR into main, then the changesets action -# will publish the changes to npm. -# -# For more info about this workflow, see: -# https://github.com/changesets/action#usage -jobs: - release: - name: Release - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest] - node-version: [20.x] - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Install & cache node_modules - uses: ./.github/actions/shared-node-cache - with: - node-version: ${{ matrix.node-version }} - ssh-private-key: ${{ secrets.KHAN_ACTIONS_BOT_SSH_PRIVATE_KEY }} - - - name: Build Storybook - # Generate a static version of storybook inside "storybook-static/" - run: yarn build-storybook - - - name: Deploy to GitHub pages - uses: JamesIves/github-pages-deploy-action@v4.5.0 - with: - # The branch the action should deploy to. - branch: gh-pages - # The folder the action should deploy. - folder: storybook-static - - - name: Create Release Pull Request or Publish to npm - id: changesets - uses: changesets/action@v1 - with: - publish: yarn publish:ci - env: - # We use a Personal Access Token here rather than the GITHUB_TOKEN - # so that it will trigger our other actions. The token has to be on - # the account of someone with appropriate access levels and given the - # repo scope. - GITHUB_TOKEN: ${{ secrets.KHAN_ACTIONS_BOT_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - - - name: Send a Slack notification if a publish fails - if: failure() - uses: rtCamp/action-slack-notify@v2 - env: - SLACK_WEBHOOK: ${{ secrets.SLACK_EXERCISENEXT_WEBHOOK }} - SLACK_CHANNEL: team-lc-perseus - SLACK_MSG_AUTHOR: ${{ github.event.pull_request.user.login }} - SLACK_USERNAME: GithubGoose - SLACK_ICON_EMOJI: ":goose:" - SLACK_MESSAGE: "Something went wrong with the release of ${{ github.event.repository.name }}. \nPlease check the logs → https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" - SLACK_TITLE: "Oops! I'm the Bad News Goose!" - SLACK_FOOTER: Perseus Slack Notification - MSG_MINIMAL: true - - - name: Send a Slack notification for web if a publish happens - if: steps.changesets.outputs.published == 'true' - uses: rtCamp/action-slack-notify@v2 - env: - SLACK_WEBHOOK: ${{ secrets.SLACK_EXERCISENEXT_WEBHOOK }} - SLACK_CHANNEL: team-lc-perseus - SLACK_MSG_AUTHOR: ${{ github.event.pull_request.user.login }} - SLACK_USERNAME: GithubGoose - SLACK_ICON_EMOJI: ":goose:" - SLACK_MESSAGE: "A new version of ${{ github.event.repository.name }} was published! \nRelease notes → https://github.com/${{ github.repository }}/releases/" - SLACK_TITLE: "New Perseus release!" - SLACK_FOOTER: Perseus Slack Notification - MSG_MINIMAL: true