-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add checks to release pull request
- Loading branch information
1 parent
5b65537
commit 3640080
Showing
32 changed files
with
1,113 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,13 +8,34 @@ on: | |
ref: | ||
required: true | ||
type: string | ||
check-sha: | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
lint-all: | ||
name: Lint All | ||
if: github.repository_owner == 'npm' | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: bash | ||
steps: | ||
- name: Create Check | ||
uses: LouisBrunner/[email protected] | ||
id: check | ||
|
||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
status: in_progress | ||
name: Lint All | ||
sha: ${{ inputs.check-sha }} | ||
# XXX: this does not work when using the default GITHUB_TOKEN. | ||
# Instead we post the main job url to the PR as a comment which | ||
# will link to all the other checks. To work around this we would | ||
# need to create a GitHub that would create on-demand tokens. | ||
# https://github.com/LouisBrunner/checks-action/issues/18 | ||
# details_url: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
|
@@ -37,6 +58,13 @@ jobs: | |
run: npm run lint --ignore-scripts | ||
- name: Post Lint | ||
run: npm run postlint --ignore-scripts | ||
- name: Conclude Check | ||
uses: LouisBrunner/[email protected] | ||
if: always() | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
conclusion: ${{ job.status }} | ||
check_id: ${{ steps.check.outputs.check_id }} | ||
|
||
test-all: | ||
name: Test All - ${{ matrix.platform.name }} - Node ${{ matrix.node-version }} | ||
|
@@ -66,6 +94,21 @@ jobs: | |
run: | ||
shell: ${{ matrix.platform.shell }} | ||
steps: | ||
- name: Create Check | ||
uses: LouisBrunner/[email protected] | ||
id: check | ||
|
||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
status: in_progress | ||
name: Test All - ${{ matrix.platform.name }} - Node ${{ matrix.node-version }} | ||
sha: ${{ inputs.check-sha }} | ||
# XXX: this does not work when using the default GITHUB_TOKEN. | ||
# Instead we post the main job url to the PR as a comment which | ||
# will link to all the other checks. To work around this we would | ||
# need to create a GitHub that would create on-demand tokens. | ||
# https://github.com/LouisBrunner/checks-action/issues/18 | ||
# details_url: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
|
@@ -102,3 +145,10 @@ jobs: | |
run: echo "::add-matcher::.github/matchers/tap.json" | ||
- name: Test | ||
run: npm test --ignore-scripts -ws -iwr --if-present | ||
- name: Conclude Check | ||
uses: LouisBrunner/[email protected] | ||
if: always() | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
conclusion: ${{ job.status }} | ||
check_id: ${{ steps.check.outputs.check_id }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,15 +11,24 @@ on: | |
permissions: | ||
contents: write | ||
pull-requests: write | ||
checks: write | ||
|
||
jobs: | ||
release-please: | ||
name: Release Please | ||
release: | ||
outputs: | ||
pr: ${{ steps.release.outputs.pr }} | ||
release: ${{ steps.release.outputs.release }} | ||
releases: ${{ steps.release.outputs.releases }} | ||
release-flags: ${{ steps.release.outputs.release-flags }} | ||
branch: ${{ steps.release.outputs.pr-branch }} | ||
pr-number: ${{ steps.release.outputs.pr-number }} | ||
comment-id: ${{ steps.pr-comment.outputs.result }} | ||
check-id: ${{ steps.check.outputs.check_id }} | ||
name: Release | ||
if: github.repository_owner == 'npm' | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: bash | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
@@ -37,29 +46,72 @@ jobs: | |
run: npm -v | ||
- name: Install Dependencies | ||
run: npm i --ignore-scripts --no-audit --no-fund | ||
- name: npx template-oss-release-please ${{ github.ref_name }} | ||
- name: Release Please | ||
id: release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: npx --offline template-oss-release-please ${{ github.ref_name }} | ||
run: | | ||
npx --offline template-oss-release-please ${{ github.ref_name }} | ||
- name: Post Pull Request Comment | ||
if: steps.release.outputs.pr-number | ||
uses: actions/github-script@v6 | ||
id: pr-comment | ||
env: | ||
PR_NUMBER: ${{ steps.release.outputs.pr-number }} | ||
with: | ||
script: | | ||
const repo = { owner: context.repo.owner, repo: context.repo.repo } | ||
const issue = { ...repo, issue_number: process.env.PR_NUMBER } | ||
post-pr: | ||
name: Post Pull Request | ||
needs: release-please | ||
if: needs.release-please.outputs.pr | ||
runs-on: ubuntu-latest | ||
const { data: workflow } = await github.rest.actions.getWorkflowRun({ ...repo, run_id: context.runId }) | ||
let body = '## Release Manager\n\n' | ||
const comments = await github.paginate(github.rest.issues.listComments, issue) | ||
let commentId = comments?.find(c => c.user.login === 'github-actions[bot]' && c.body.startsWith(body))?.id | ||
body += `- Release workflow run: ${workflow.html_url}` | ||
if (commentId) { | ||
await github.rest.issues.updateComment({ ...repo, comment_id: commentId, body }) | ||
} else { | ||
const { data: comment } = await github.rest.issues.createComment({ ...issue, body }) | ||
commentId = comment?.id | ||
} | ||
return commentId | ||
- name: Create Check | ||
uses: LouisBrunner/[email protected] | ||
id: check | ||
if: steps.release.outputs.pr-number | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
status: in_progress | ||
name: Release | ||
sha: ${{ steps.release.outputs.pr-sha }} | ||
# XXX: this does not work when using the default GITHUB_TOKEN. | ||
# Instead we post the main job url to the PR as a comment which | ||
# will link to all the other checks. To work around this we would | ||
# need to create a GitHub that would create on-demand tokens. | ||
# https://github.com/LouisBrunner/checks-action/issues/18 | ||
# details_url: | ||
|
||
update: | ||
needs: release | ||
outputs: | ||
ref: ${{ steps.ref.outputs.branch }} | ||
sha: ${{ steps.commit.outputs.sha }} | ||
check-id: ${{ steps.check.outputs.check_id }} | ||
name: Update - Release | ||
if: github.repository_owner == 'npm' && needs.release.outputs.pr | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: bash | ||
steps: | ||
- name: Output PR Head Branch | ||
id: ref | ||
run: echo "::set-output name=branch::${{ fromJSON(needs.release-please.outputs.pr).headBranchName }}" | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ steps.ref.outputs.branch }} | ||
ref: ${{ needs.release.outputs.branch }} | ||
- name: Setup Git User | ||
run: | | ||
git config --global user.email "[email protected]" | ||
|
@@ -75,30 +127,89 @@ jobs: | |
- name: Install Dependencies | ||
run: npm i --ignore-scripts --no-audit --no-fund | ||
- name: Run Post Pull Request Actions | ||
run: npm run rp-pull-request --ignore-scripts -ws -iwr --if-present | ||
- name: Commit and Push | ||
env: | ||
RELEASE_PR_NUMBER: ${{ needs.release.outputs.pr-number }} | ||
RELEASE_COMMENT_ID: ${{ needs.release.outputs.comment-id }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
npm run rp-pull-request --ignore-scripts -ws -iwr --if-present | ||
- name: Commit | ||
id: commit | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
git commit -am "chore: post pull request" || true | ||
echo "::set-output sha=$(git rev-parse HEAD)" | ||
git push | ||
git commit --all --amend --no-edit || true | ||
git push --force-with-lease | ||
echo "::set-output name=sha::$(git rev-parse HEAD)" | ||
- name: Create Check | ||
uses: LouisBrunner/[email protected] | ||
id: check | ||
|
||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
status: in_progress | ||
name: Release | ||
sha: ${{ steps.commit.outputs.sha }} | ||
# XXX: this does not work when using the default GITHUB_TOKEN. | ||
# Instead we post the main job url to the PR as a comment which | ||
# will link to all the other checks. To work around this we would | ||
# need to create a GitHub that would create on-demand tokens. | ||
# https://github.com/LouisBrunner/checks-action/issues/18 | ||
# details_url: | ||
- name: Conclude Check | ||
uses: LouisBrunner/[email protected] | ||
if: always() | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
conclusion: ${{ job.status }} | ||
check_id: ${{ needs.release.outputs.check-id }} | ||
|
||
release-test: | ||
name: Test | ||
needs: post-pr | ||
if: needs.post-pr.outputs.ref | ||
ci: | ||
name: CI - Release | ||
needs: [ release, update ] | ||
if: needs.release.outputs.pr | ||
uses: ./.github/workflows/ci-release.yml | ||
with: | ||
ref: ${{ needs.post-pr.outputs.ref }} | ||
sha: ${{ needs.post-pr.outputs.sha }} | ||
ref: ${{ needs.release.outputs.branch }} | ||
check-sha: ${{ needs.update.outputs.sha }} | ||
|
||
post-ci: | ||
needs: [ release, update, ci ] | ||
name: Post CI - Release | ||
if: github.repository_owner == 'npm' && needs.release.outputs.pr && always() | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: bash | ||
steps: | ||
- name: Get Needs Result | ||
id: needs-result | ||
run: | | ||
result="" | ||
if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then | ||
result="failure" | ||
elif [[ "${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then | ||
result="cancelled" | ||
else | ||
result="success" | ||
fi | ||
echo "::set-output name=result::$result" | ||
- name: Conclude Check | ||
uses: LouisBrunner/[email protected] | ||
if: always() | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
conclusion: ${{ steps.needs-result.outputs.result }} | ||
check_id: ${{ needs.update.outputs.check-id }} | ||
|
||
post-release: | ||
name: Post Release | ||
needs: release-please | ||
if: github.repository_owner == 'npm' && needs.release-please.outputs.release | ||
needs: release | ||
name: Post Release - Release | ||
if: github.repository_owner == 'npm' && needs.release.outputs.releases | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: bash | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
@@ -117,5 +228,7 @@ jobs: | |
- name: Install Dependencies | ||
run: npm i --ignore-scripts --no-audit --no-fund | ||
- name: Run Post Release Actions | ||
env: | ||
RELEASES: ${{ needs.release.outputs.releases }} | ||
run: | | ||
npm run rp-release --ignore-scripts -ws -iwr --if-present | ||
npm run rp-release --ignore-scripts --if-present ${{ join(fromJSON(needs.release.outputs.release-flags), ' ') }} |
Oops, something went wrong.