From 7c5601a3c0115b5e31c7ad48790095c368a1951f Mon Sep 17 00:00:00 2001 From: Jeppe Reinhold Date: Wed, 19 Jul 2023 11:01:08 +0200 Subject: [PATCH 1/4] re-enable canary releases --- ...y-release-pr.WIP => canary-release-pr.yml} | 59 ++++++++++++------- 1 file changed, 37 insertions(+), 22 deletions(-) rename .github/workflows/{canary-release-pr.WIP => canary-release-pr.yml} (51%) diff --git a/.github/workflows/canary-release-pr.WIP b/.github/workflows/canary-release-pr.yml similarity index 51% rename from .github/workflows/canary-release-pr.WIP rename to .github/workflows/canary-release-pr.yml index 0c5948948959..c5b62484b9bf 100644 --- a/.github/workflows/canary-release-pr.WIP +++ b/.github/workflows/canary-release-pr.yml @@ -1,18 +1,20 @@ name: Publish canary release of PR -run-name: 'Canary release: PR #${{ github.event.pull_request.number }} at ${{ github.sha }}' +run-name: 'Canary release: PR #${{ inputs.pr }}, triggered by ${{ github.triggering_actor }}' on: - pull_request: - types: [opened, synchronize, reopened] - branches: - - next + workflow_dispatch: + inputs: + pr: + description: 'Which pull request number to create a canary release for' + required: true + type: number env: PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1 PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: 1 concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number }} + group: ${{ github.workflow }}-${{ inputs.pr }} cancel-in-progress: true permissions: @@ -22,13 +24,30 @@ jobs: release-canary: name: Release canary version runs-on: ubuntu-latest - environment: canary-release + environment: release defaults: run: working-directory: scripts steps: + # TODO: check triggering permssions + + - name: Get Pull Request information + id: info + run: | + PR_INFO=$(gh pr view ${{ inputs.pr }} --json isCrossRepository,headRefOid,headRefName,headRepository,headRepositoryOwner --jq '{isFork: .isCrossRepository, owner: .headRepositoryOwner.login, name: .headRepository.name, branch: .headRefName, sha: .headRefOid}') + echo $PR_INFO + # Loop through each key-value pair in PR_INFO and set as step output + for key in $(echo "$PR_INFO" | jq -r 'keys[]'); do + value=$(echo "$PR_INFO" | jq -r ".$key") + echo "$key=$value" >> "$GITHUB_OUTPUT" + done + - name: Checkout uses: actions/checkout@v3 + with: + repository: ${{ steps.info.outputs.isFork == 'true' && format('{0}/{1}', steps.info.outputs.owner, steps.info.outputs.repository) || null }} + ref: ${{ steps.info.outputs.sha }} + token: ${{ secrets.GH_TOKEN }} - name: Setup Node.js uses: actions/setup-node@v3 @@ -53,21 +72,25 @@ jobs: - name: Set version id: version run: | - SHORT_SHA=$(git rev-parse --short ${{ github.sha }}) - yarn release:version --release-type prerelease --pre-id pr-${{ github.event.pull_request.number }}-$SHORT_SHA --verbose + TIMESTAMP=$(date +%s) + SHORT_SHA=$(git rev-parse --short ${{ steps.info.outputs.sha }}) + yarn release:version --release-type prerelease --pre-id pr-${{ inputs.pr }}-$SHORT_SHA-$TIMESTAMP --verbose - name: Publish v${{ steps.version.outputs.next-version }} env: YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - run: yarn release:publish --tag pr-${{ github.event.pull_request.number }} --verbose + run: yarn release:publish --tag pr-${{ inputs.pr }} --verbose + + # TODO: build summary table + # TODO: change PR description instead - name: Create comment on PR env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - gh pr comment ${{ github.event.pull_request.number }}\ + gh pr comment ${{ inputs.pr }}\ --repo "${{github.repository }}"\ - --body "🚀 This pull request has been published as version \`${{ steps.version.outputs.next-version }}\` and with the tag \`pr-${{ github.event.pull_request.number }}\`. + --body "🚀 This pull request has been published as version \`${{ steps.version.outputs.next-version }}\` and with the tag \`pr-${{ inputs.pr }}\` (at commit \`${{ steps.info.outputs.sha }}\`). [You can see it on the npm registry here](https://npmjs.com/package/@storybook/cli/v/${{ steps.version.outputs.next-version }})". - name: Create failing comment on PR @@ -75,14 +98,6 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - gh pr comment ${{ github.event.pull_request.number }}\ + gh pr comment ${{ inputs.pr }}\ --repo "${{github.repository }}"\ - --body "Failed to publish canary version of this pul request. See the failed workflow run at See run at: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" - - # - name: Report failure to Discord - # if: failure() - # env: - # DISCORD_WEBHOOK: ${{ secrets.DISCORD_MONITORING_URL }} - # uses: Ilshidur/action-discord@master - # with: - # args: 'The GitHub Action for publishing version ${{ steps.version.outputs.current-version }} (triggered by ${{ github.triggering_actor }}) failed! See run at: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' + --body "Failed to publish canary version of this pull request at commit \`${{ steps.info.outputs.sha }}\`. See the failed workflow run at: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" From 3ab40b8023a1c8477de02398bd9fdbefca55ead3 Mon Sep 17 00:00:00 2001 From: Jeppe Reinhold Date: Wed, 19 Jul 2023 11:12:45 +0200 Subject: [PATCH 2/4] add permissions check --- .github/workflows/canary-release-pr.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/canary-release-pr.yml b/.github/workflows/canary-release-pr.yml index c5b62484b9bf..b423d44e1ae8 100644 --- a/.github/workflows/canary-release-pr.yml +++ b/.github/workflows/canary-release-pr.yml @@ -29,9 +29,12 @@ jobs: run: working-directory: scripts steps: - # TODO: check triggering permssions + - name: Fail if triggerer is not administrator + uses: prince-chrismc/check-actor-permissions-action@v2.0.4 + with: + permission: admin - - name: Get Pull Request information + - name: Get pull request information id: info run: | PR_INFO=$(gh pr view ${{ inputs.pr }} --json isCrossRepository,headRefOid,headRefName,headRepository,headRepositoryOwner --jq '{isFork: .isCrossRepository, owner: .headRepositoryOwner.login, name: .headRepository.name, branch: .headRefName, sha: .headRefOid}') From 4d1287aabc8a2050b7873ba255f9d1bed47c6b00 Mon Sep 17 00:00:00 2001 From: Jeppe Reinhold Date: Wed, 19 Jul 2023 11:19:01 +0200 Subject: [PATCH 3/4] make the workflow a no-op --- .github/workflows/canary-release-pr.yml | 77 +------------------------ 1 file changed, 2 insertions(+), 75 deletions(-) diff --git a/.github/workflows/canary-release-pr.yml b/.github/workflows/canary-release-pr.yml index b423d44e1ae8..2a90a4746770 100644 --- a/.github/workflows/canary-release-pr.yml +++ b/.github/workflows/canary-release-pr.yml @@ -29,78 +29,5 @@ jobs: run: working-directory: scripts steps: - - name: Fail if triggerer is not administrator - uses: prince-chrismc/check-actor-permissions-action@v2.0.4 - with: - permission: admin - - - name: Get pull request information - id: info - run: | - PR_INFO=$(gh pr view ${{ inputs.pr }} --json isCrossRepository,headRefOid,headRefName,headRepository,headRepositoryOwner --jq '{isFork: .isCrossRepository, owner: .headRepositoryOwner.login, name: .headRepository.name, branch: .headRefName, sha: .headRefOid}') - echo $PR_INFO - # Loop through each key-value pair in PR_INFO and set as step output - for key in $(echo "$PR_INFO" | jq -r 'keys[]'); do - value=$(echo "$PR_INFO" | jq -r ".$key") - echo "$key=$value" >> "$GITHUB_OUTPUT" - done - - - name: Checkout - uses: actions/checkout@v3 - with: - repository: ${{ steps.info.outputs.isFork == 'true' && format('{0}/{1}', steps.info.outputs.owner, steps.info.outputs.repository) || null }} - ref: ${{ steps.info.outputs.sha }} - token: ${{ secrets.GH_TOKEN }} - - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: '16' - - - name: Cache dependencies - uses: actions/cache@v3 - with: - path: | - ~/.yarn/berry/cache - key: yarn-v1-${{ hashFiles('scripts/yarn.lock') }}-${{ hashFiles('code/yarn.lock') }} - restore-keys: | - yarn-v1-${{ hashFiles('scripts/yarn.lock') }}-${{ hashFiles('code/yarn.lock') }} - yarn-v1-${{ hashFiles('scripts/yarn.lock') }} - yarn-v1 - - - name: Install dependencies - working-directory: . - run: yarn task --task=install --start-from=install - - - name: Set version - id: version - run: | - TIMESTAMP=$(date +%s) - SHORT_SHA=$(git rev-parse --short ${{ steps.info.outputs.sha }}) - yarn release:version --release-type prerelease --pre-id pr-${{ inputs.pr }}-$SHORT_SHA-$TIMESTAMP --verbose - - - name: Publish v${{ steps.version.outputs.next-version }} - env: - YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - run: yarn release:publish --tag pr-${{ inputs.pr }} --verbose - - # TODO: build summary table - - # TODO: change PR description instead - - name: Create comment on PR - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - gh pr comment ${{ inputs.pr }}\ - --repo "${{github.repository }}"\ - --body "🚀 This pull request has been published as version \`${{ steps.version.outputs.next-version }}\` and with the tag \`pr-${{ inputs.pr }}\` (at commit \`${{ steps.info.outputs.sha }}\`). - [You can see it on the npm registry here](https://npmjs.com/package/@storybook/cli/v/${{ steps.version.outputs.next-version }})". - - - name: Create failing comment on PR - if: failure() - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - gh pr comment ${{ inputs.pr }}\ - --repo "${{github.repository }}"\ - --body "Failed to publish canary version of this pull request at commit \`${{ steps.info.outputs.sha }}\`. See the failed workflow run at: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" + - name: Do nothing + run: "I'm not doing anything" From 39c72fac2c7d976efb717f1822474a0e2154504d Mon Sep 17 00:00:00 2001 From: Jeppe Reinhold Date: Wed, 19 Jul 2023 11:21:01 +0200 Subject: [PATCH 4/4] add echo --- .github/workflows/canary-release-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/canary-release-pr.yml b/.github/workflows/canary-release-pr.yml index 2a90a4746770..c12b0ca566b6 100644 --- a/.github/workflows/canary-release-pr.yml +++ b/.github/workflows/canary-release-pr.yml @@ -30,4 +30,4 @@ jobs: working-directory: scripts steps: - name: Do nothing - run: "I'm not doing anything" + run: echo "I'm not doing anything"