From b4f7de26155e09a4ce7cab0ad5364664c765ac1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A5=E5=9B=BD=E5=AE=87?= <841185308@qq.com> Date: Fri, 30 Jun 2023 11:24:11 +0800 Subject: [PATCH] Package by pr comment and update @electron/notarize to 2.0.0 (#2750) * chore(CI): Use comment command to package * feat: update notarize to 2.0.0 * chore: prettier notarize.js --- .github/workflows/comment_for_pr_package.yml | 43 ---------- .github/workflows/package_for_test.yml | 84 ++++++++++++++------ packages/neuron-wallet/package.json | 2 +- packages/neuron-wallet/scripts/notarize.js | 20 ++--- yarn.lock | 8 +- 5 files changed, 74 insertions(+), 83 deletions(-) delete mode 100644 .github/workflows/comment_for_pr_package.yml diff --git a/.github/workflows/comment_for_pr_package.yml b/.github/workflows/comment_for_pr_package.yml deleted file mode 100644 index 84c01489ab..0000000000 --- a/.github/workflows/comment_for_pr_package.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: Comment on the pull request - -on: - workflow_run: - workflows: ["Package Neuron for Test"] - types: - - completed - -jobs: - comment: - name: Append links to the Pull Request - runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'success' }} - steps: - - id: download_artifact - uses: dawidd6/action-download-artifact@v2 - continue-on-error: true - with: - name: package_info - run_id: ${{ github.event.workflow_run.id }} - - - name: if non exist, skip comment - if: ${{ steps.download_artifact.outcome == 'failure' }} - run: exit 0 - - - id: pr_number - run: | - export PR_NUM=$(cat ./pr_number) - echo "pr_num=$PR_NUM" >> $GITHUB_OUTPUT - - id: run_id - run: | - export RUN_ID=$(cat ./run_id) - echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT - - id: sha - run: | - export SHA=$(cat ./sha) - echo "sha=$SHA" >> $GITHUB_OUTPUT - - uses: thollander/actions-comment-pull-request@v2 - if: ${{ steps.pr_number.outputs.pr_num != '' && steps.run_id.outputs.run_id != '' }} - with: - message: | - Packaging for test is done in [${{ steps.run_id.outputs.run_id }}](https://github.com/${{github.repository}}/actions/runs/${{steps.run_id.outputs.run_id}}) for commit https://github.com/${{github.repository}}/pull/${{steps.pr_number.outputs.pr_num}}/commits/${{steps.sha.outputs.sha}} . - pr_number: ${{ steps.pr_number.outputs.pr_num }} diff --git a/.github/workflows/package_for_test.yml b/.github/workflows/package_for_test.yml index a337e816eb..b9d02b1f26 100644 --- a/.github/workflows/package_for_test.yml +++ b/.github/workflows/package_for_test.yml @@ -1,11 +1,31 @@ name: Package Neuron for Test -on: - pull_request: +on: + issue_comment: + types: [created, edited] push: jobs: + check_command: + runs-on: ubuntu-latest + ## skip if trigger by issue comment but not pr comment + if: ${{ (github.event_name == 'issue_comment' && github.event.issue.pull_request) || github.event_name == 'push' }} + permissions: + pull-requests: write + steps: + - name: Check for package command + uses: xt0rted/slash-command-action@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + command: package + reaction: "true" + reaction-type: "eyes" + allow-edits: "true" + permission-level: write + packaging: + needs: [check_command] + strategy: matrix: node: @@ -18,6 +38,7 @@ jobs: runs-on: ${{ matrix.os }} name: ${{ matrix.os }}(Node.js ${{ matrix.node }}) + env: MAC_SHOULD_CODE_SIGN: ${{ github.event_name != 'pull_request' && secrets.APPLE_ID != '' }} WIN_CERTIFICATE_BASE64: ${{ secrets.WIN_CERTIFICATE_BASE64 }} @@ -28,8 +49,17 @@ jobs: git config --global core.autocrlf false git config --global core.eol lf + - name: Get PR Branch + if: github.event_name == 'issue_comment' + id: comment-branch + uses: xt0rted/pull-request-comment-branch@v1 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + - name: Checkout uses: actions/checkout@v3 + with: + ref: ${{ steps.comment-branch.outputs.ref }} - name: Setup Node uses: actions/setup-node@v3 @@ -160,35 +190,37 @@ jobs: name: Neuron-Linux path: release/Neuron-*.AppImage - cache-package-info: + comment_when_package_success: needs: [packaging] - if: ${{ github.event_name == 'pull_request' }} + name: Append links to the Pull Request runs-on: ubuntu-latest steps: - - name: Save PR number and run id - env: - PR_NUMBER: ${{ github.event.number }} - RUN_ID: ${{ github.run_id }} - SHA: ${{ github.event.pull_request.head.sha }} - run: | - mkdir -p ./package_info - echo $PR_NUMBER > ./package_info/pr_number - echo $RUN_ID > ./package_info/run_id - echo $SHA > ./package_info/sha - - uses: actions/upload-artifact@v3 + - name: Comment by push event + if: ${{ github.event_name == 'push' }} + uses: peter-evans/commit-comment@v2 + with: + body: | + Packaging for test is done in [${{ github.run_id }}](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) + + - name: Comment by pull request comment event + if: ${{ github.event_name == 'issue_comment' }} + uses: peter-evans/create-or-update-comment@v3 with: - name: package_info - path: package_info/ - retention-days: 3 - comment: + comment-id: ${{ github.event.comment.id }} + body: | + Packaging for test is done in [${{ github.run_id }}](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}). @${{ github.event.comment.user.login }} + edit-mode: append + + comment_when_package_failed: needs: [packaging] - # During a pull_request event triggered by a forked repository, actions have no write access to GitHub resources and will fail on any attempt. - # ref https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#restrictions-on-repository-forks - if: ${{ github.event_name == 'push' }} - name: Append links to the Pull Request + if: ${{ always() && needs.packaging.result == 'failure' }} + name: Append failed comment to the comment runs-on: ubuntu-latest steps: - - uses: peter-evans/commit-comment@v2 + - name: Comment by pull request comment event when package failed + if: ${{ github.event_name == 'issue_comment' }} + uses: peter-evans/create-or-update-comment@v3 with: - body: | - Packaging for test is done in [${{ github.run_id }}](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) + comment-id: ${{ github.event.comment.id }} + body: Packageing failed in [${{ github.run_id }}](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}). @${{ github.event.comment.user.login }} + edit-mode: append diff --git a/packages/neuron-wallet/package.json b/packages/neuron-wallet/package.json index 954261f0b2..f972c3a8ec 100644 --- a/packages/neuron-wallet/package.json +++ b/packages/neuron-wallet/package.json @@ -68,7 +68,7 @@ "uuid": "8.3.2" }, "devDependencies": { - "@electron/notarize": "1.2.4", + "@electron/notarize": "2.0.0", "@nervosnetwork/ckb-types": "0.109.0", "@types/archiver": "3.1.1", "@types/async": "3.2.20", diff --git a/packages/neuron-wallet/scripts/notarize.js b/packages/neuron-wallet/scripts/notarize.js index 2e5d5e8398..c10b8d0627 100644 --- a/packages/neuron-wallet/scripts/notarize.js +++ b/packages/neuron-wallet/scripts/notarize.js @@ -1,7 +1,7 @@ const { notarize } = require('@electron/notarize') exports.default = async function notarizing(context) { - const { electronPlatformName, appOutDir } = context; + const { electronPlatformName, appOutDir } = context if (electronPlatformName !== 'darwin') { return } @@ -11,26 +11,28 @@ exports.default = async function notarizing(context) { return Promise.resolve('skip') } - const appleId = process.env.APPLE_ID; - const appleIdPassword = process.env.APPLE_ID_PASSWORD; + const appleId = process.env.APPLE_ID + const appleIdPassword = process.env.APPLE_ID_PASSWORD + const teamId = process.env.TEAM_ID - if (!appleId || !appleIdPassword) { - console.warn(`${appleId ? "Apple id password" : "Apple id"} is not found`) + if (!appleId || !appleIdPassword || !teamId) { + console.warn(`${appleId ? (appleIdPassword ? 'Team id' : 'Apple id password') : 'Apple id'} is not found`) process.exit(1) } const appName = context.packager.appInfo.productFilename - console.info("Notarization started") + console.info('Notarization started') try { await notarize({ appBundleId: 'com.nervos.neuron', appPath: `${appOutDir}/${appName}.app`, - appleId: appleId, - appleIdPassword: appleIdPassword, + appleId, + appleIdPassword, + teamId, }) - console.info("Notarization finished") + console.info('Notarization finished') } catch (err) { console.error(err) process.exit(1) diff --git a/yarn.lock b/yarn.lock index fa23ecf513..4937be6e0a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1650,10 +1650,10 @@ optionalDependencies: global-agent "^3.0.0" -"@electron/notarize@1.2.4": - version "1.2.4" - resolved "https://registry.yarnpkg.com/@electron/notarize/-/notarize-1.2.4.tgz#a7d38773f4cad40df111a5edc64037e5d768ea1e" - integrity sha512-W5GQhJEosFNafewnS28d3bpQ37/s91CDWqxVchHfmv2dQSTWpOzNlUVQwYzC1ay5bChRV/A9BTL68yj0Pa+TSg== +"@electron/notarize@2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@electron/notarize/-/notarize-2.0.0.tgz#4df39e817264746aa9bd779e0091b6c441715b72" + integrity sha512-dqDpd2YCgl6PHJgXEuKGYH3+L4GIGV7ZbKYJjJv66ed+hVPxZA+GAL5JH8/hCnoyQa8WzJTzqd+qhiL5Oxr+SA== dependencies: debug "^4.1.1" fs-extra "^9.0.1"