Skip to content

Commit

Permalink
chore: ci: fix branch protection issue (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaStevens authored Feb 22, 2023
1 parent 7e53f59 commit e9b1a1b
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 65 deletions.
57 changes: 57 additions & 0 deletions .github/actions/protection-main/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Protect main
description: Delete branch protection on main

runs:
using: "composite"
steps:
- name: Recreate branch protection on main
uses: actions/github-script@v6.4.0
with:
github-token: ${{ secrets.ACCESS_TOKEN }}
# Note: keep this inline script in sync with script/setup.js!
# Todo: it would be nice to not have two sources of truth...
# https://github.com/JoshuaKGoldberg/template-typescript-node-package/issues/145
script: |
github.request(
`PUT /repos/JoshuaKGoldberg/ts-api-utils/branches/main/protection`,
{
allow_deletions: false,
allow_force_pushes: true,
allow_fork_pushes: false,
allow_fork_syncing: true,
block_creations: false,
branch: "main",
enforce_admins: false,
owner: "JoshuaKGoldberg",
repo: "ts-api-utils",
required_conversation_resolution: true,
required_linear_history: false,
required_pull_request_reviews: null,
required_status_checks: {
checks: [
{ context: "build (16.13.0)" },
{ context: "build (18.x)" },
{ context: "compliance" },
{ context: "docs" },
{ context: "knip" },
{ context: "lint" },
{ context: "markdown" },
{ context: "package" },
{ context: "packages" },
{ context: "prettier" },
{ context: "spelling" },
{ context: "test (16.13.0, 4.2.4)" },
{ context: "test (16.13.0, 4.3.5)" },
{ context: "test (16.13.0, 4.4.4)" },
{ context: "test (16.13.0, latest)" },
{ context: "test (18.x, 4.2.4)" },
{ context: "test (18.x, 4.3.5)" },
{ context: "test (18.x, 4.4.4)" },
{ context: "test (18.x, latest)" },
{ context: "type-check" },
],
strict: false,
},
restrictions: null,
}
);
20 changes: 20 additions & 0 deletions .github/actions/unprotect-main/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Unprotect main
description: Delete branch protection on main

runs:
using: "composite"
steps:
- name: Delete branch protection on main
uses: actions/github-script@v6.4.0
with:
github-token: ${{ secrets.ACCESS_TOKEN }}
script: |
try {
await github.request(
`DELETE /repos/JoshuaKGoldberg/ts-api-utils/branches/main/protection`,
);
} catch (error) {
if (!error.message?.includes?.("Branch not protected")) {
throw error;
}
}
7 changes: 7 additions & 0 deletions .github/workflows/release-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,15 @@ jobs:
run: cp ./docs/generated/v$PACKAGE_VERSION/coverage.svg ./docs/coverage.svg

- run: echo "COVERAGE_CHANGED=$(git status --porcelain -u | grep -c docs/coverage.svg)" >> $GITHUB_ENV

- if: ${{ env.COVERAGE_CHANGED != '0' }}
uses: ./.github/actions/unprotect-main/action.yml

- if: ${{ env.COVERAGE_CHANGED != '0' }}
run: |
git add docs/coverage.svg
git commit -m "docs: updated documentation coverage"
git push
- if: ${{ always() && env.COVERAGE_CHANGED != '0' }}
uses: ./.github/actions/protect-main/action.yml
67 changes: 2 additions & 65 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,76 +24,13 @@ jobs:
- env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
- name: Delete branch protection on main
uses: actions/github-script@v6.4.0
with:
github-token: ${{ secrets.ACCESS_TOKEN }}
script: |
try {
await github.request(
`DELETE /repos/JoshuaKGoldberg/ts-api-utils/branches/main/protection`,
);
} catch (error) {
if (!error.message?.includes?.("Branch not protected")) {
throw error;
}
}
- uses: .github/actions/unprotect-main/action.yml
- run: echo "SHOULD_RELEASE=$(pnpm run should-semantic-release &> /dev/null && echo '1' || echo '0')"
- if: ${{ env.SHOULD_RELEASE != '0' }}
env:
GITHUB_TOKEN: ${{ github.token }}
run: pnpm release-it --verbose
- if: always()
name: Recreate branch protection on main
uses: actions/github-script@v6.4.0
with:
github-token: ${{ secrets.ACCESS_TOKEN }}
# Note: keep this inline script in sync with script/setup.js!
# Todo: it would be nice to not have two sources of truth...
# https://github.com/JoshuaKGoldberg/template-typescript-node-package/issues/145
script: |
github.request(
`PUT /repos/JoshuaKGoldberg/ts-api-utils/branches/main/protection`,
{
allow_deletions: false,
allow_force_pushes: true,
allow_fork_pushes: false,
allow_fork_syncing: true,
block_creations: false,
branch: "main",
enforce_admins: false,
owner: "JoshuaKGoldberg",
repo: "ts-api-utils",
required_conversation_resolution: true,
required_linear_history: false,
required_pull_request_reviews: null,
required_status_checks: {
checks: [
{ context: "build (16.13.0)" },
{ context: "build (18.x)" },
{ context: "compliance" },
{ context: "docs" },
{ context: "knip" },
{ context: "lint" },
{ context: "markdown" },
{ context: "package" },
{ context: "packages" },
{ context: "prettier" },
{ context: "spelling" },
{ context: "test (16.13.0, 4.2.4)" },
{ context: "test (16.13.0, 4.3.5)" },
{ context: "test (16.13.0, 4.4.4)" },
{ context: "test (16.13.0, latest)" },
{ context: "test (18.x, 4.2.4)" },
{ context: "test (18.x, 4.3.5)" },
{ context: "test (18.x, 4.4.4)" },
{ context: "test (18.x, latest)" },
{ context: "type-check" },
],
strict: false,
},
restrictions: null,
}
);
uses: .github/actions/protect-main/action.yml
- if: ${{ env.SHOULD_RELEASE != '0' }}
uses: ./.github/workflows/release-docs.yml@main

0 comments on commit e9b1a1b

Please sign in to comment.