From 8b6a57f39e2e9605f809ed7069a579136afdda23 Mon Sep 17 00:00:00 2001 From: ishiko732 Date: Mon, 20 Nov 2023 22:54:40 +0800 Subject: [PATCH] Fix/GitHub Action --- .github/workflows/deploy.yml | 46 ++++++++++++++------------ .github/workflows/npm-beta-publish.yml | 30 ----------------- .github/workflows/npm-publish.yml | 23 +++++++++---- .github/workflows/pr-test.yml | 24 +++----------- 4 files changed, 47 insertions(+), 76 deletions(-) delete mode 100644 .github/workflows/npm-beta-publish.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 53473c2..3afdf15 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -15,24 +15,28 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up Node.js - uses: actions/setup-node@v2 - with: - node-version: 16 - - - name: Install dependencies - run: pnpm install --frozen-lockfile - - - name: Build docs - run: pnpm run docs - - name: Copy example folder - run: cp -R example docs/example - - - name: Deploy to GitHub Pages - uses: JamesIves/github-pages-deploy-action@4.1.1 - with: - branch: gh-pages - folder: docs \ No newline at end of file + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: 16 + + - uses: pnpm/action-setup@v2.2.2 + with: + version: 8.7.1 + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Build docs + run: pnpm run docs + - name: Copy example folder + run: cp -R example docs/example + + - name: Deploy to GitHub Pages + uses: JamesIves/github-pages-deploy-action@4.1.1 + with: + branch: gh-pages + folder: docs \ No newline at end of file diff --git a/.github/workflows/npm-beta-publish.yml b/.github/workflows/npm-beta-publish.yml deleted file mode 100644 index ac93958..0000000 --- a/.github/workflows/npm-beta-publish.yml +++ /dev/null @@ -1,30 +0,0 @@ -# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created -# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages - -name: Publish Beta Package to npm.js - -on: - push: - branches: - - dev - -jobs: - publish-npm: - runs-on: ubuntu-latest - permissions: - contents: read - id-token: write - steps: - - uses: actions/checkout@v2 - - uses: pnpm/action-setup@v2.2.2 - with: - version: 8.7.1 - - run: pnpm install - - run: pnpm lint - - run: pnpm test - - run: pnpm build - - uses: JS-DevTools/npm-publish@v2 - with: - token: ${{secrets.npm_token}} - provenance: true - tag: beta \ No newline at end of file diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 1f2ae6b..a581ac5 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -5,9 +5,10 @@ name: Publish Package to npm.js on: release: - types: [published] - repository_dispatch: - types: [publish-npm] + types: [ published ] + pull_request: + types: + - closed jobs: @@ -25,7 +26,17 @@ jobs: - run: pnpm lint - run: pnpm test - run: pnpm build - - uses: JS-DevTools/npm-publish@v2 + - name: Determine Target Branch + id: determine-branch + run: echo "::set-output name=branch::${{ github.event.pull_request.base.ref }}" + + - name: Determine Tag + id: determine-tag + run: echo "::set-output name=tag::${{ steps.determine-branch.outputs.branch == 'master' && 'latest' || 'beta' }}" + + - name: Publish Package + uses: JS-DevTools/npm-publish@v2 with: - token: ${{secrets.npm_token}} - provenance: true \ No newline at end of file + token: ${{secrets.npm_token}} + provenance: true + tag: ${{ steps.determine-tag.outputs.tag }} \ No newline at end of file diff --git a/.github/workflows/pr-test.yml b/.github/workflows/pr-test.yml index 708b4c7..93b6e4b 100644 --- a/.github/workflows/pr-test.yml +++ b/.github/workflows/pr-test.yml @@ -28,30 +28,16 @@ jobs: - name: Install dependencies run: pnpm install --frozen-lockfile - - name: Run tests - run: pnpm test + + - uses: jwalton/gh-find-current-pr@v1 + id: findPr - name: jest coverage report uses: ArtiomTr/jest-coverage-report-action@v2.0-rc.6 with: github-token: ${{ secrets.GITHUB_TOKEN }} + prnumber: ${{ steps.findPr.outputs.number }} - name: Check test status id: test-status - run: echo "::set-output name=status::$(if grep -q 'Test failed' test-results.txt; then echo 'failure'; else echo 'success'; fi)" - - merge: - needs: test - runs-on: ubuntu-latest - if: ${{ needs.test.outputs.status == 'success' }} - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Trigger npm-publish workflow - uses: peter-evans/repository-dispatch@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - repository: ishiko732/ts-fsrs - event-type: publish-npm + run: echo "::set-output name=status::$(if grep -q 'Test failed' test-results.txt; then echo 'failure'; else echo 'success'; fi)" \ No newline at end of file