mirror of
https://github.com/Shik3i/KoalaSync.git
synced 2026-08-31 13:08:15 +00:00
fix(ci): limit prepared release permissions
This commit is contained in:
@@ -85,6 +85,8 @@ jobs:
|
|||||||
verify-prepared-release:
|
verify-prepared-release:
|
||||||
needs: [preflight, prepare-release]
|
needs: [preflight, prepare-release]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout prepared release commit
|
- name: Checkout prepared release commit
|
||||||
uses: actions/checkout@v7
|
uses: actions/checkout@v7
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ export function parseRemoteMain(text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function validateReleaseWorkflowContract(text) {
|
export function validateReleaseWorkflowContract(text) {
|
||||||
const workflow = String(text);
|
const workflow = String(text).replace(/\r\n/gu, '\n');
|
||||||
const image = 'ghcr.io/shik3i/koalasync';
|
const image = 'ghcr.io/shik3i/koalasync';
|
||||||
if (!workflow.includes(`IMAGE: ${image}`)) {
|
if (!workflow.includes(`IMAGE: ${image}`)) {
|
||||||
throw new Error(`release workflow must define the lowercase canonical image ${image}`);
|
throw new Error(`release workflow must define the lowercase canonical image ${image}`);
|
||||||
@@ -97,6 +97,16 @@ export function validateReleaseWorkflowContract(text) {
|
|||||||
if (/git push origin HEAD:main\s*(?:\|\||;\s*true)/u.test(workflow)) {
|
if (/git push origin HEAD:main\s*(?:\|\||;\s*true)/u.test(workflow)) {
|
||||||
throw new Error('release workflow must stop when the automatic main push fails');
|
throw new Error('release workflow must stop when the automatic main push fails');
|
||||||
}
|
}
|
||||||
|
const verificationPermissions = [
|
||||||
|
' verify-prepared-release:',
|
||||||
|
' needs: [preflight, prepare-release]',
|
||||||
|
' runs-on: ubuntu-latest',
|
||||||
|
' permissions:',
|
||||||
|
' contents: read'
|
||||||
|
].join('\n');
|
||||||
|
if (!workflow.includes(verificationPermissions)) {
|
||||||
|
throw new Error('prepared release verification must explicitly limit GITHUB_TOKEN to contents: read');
|
||||||
|
}
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,11 @@ describe('local release gate contract', () => {
|
|||||||
'node scripts/release-preflight.mjs --sources "$VERSION"',
|
'node scripts/release-preflight.mjs --sources "$VERSION"',
|
||||||
'git commit -m "chore(release): update versions to v$VERSION [skip ci]"',
|
'git commit -m "chore(release): update versions to v$VERSION [skip ci]"',
|
||||||
'git push origin HEAD:main',
|
'git push origin HEAD:main',
|
||||||
|
' verify-prepared-release:',
|
||||||
|
' needs: [preflight, prepare-release]',
|
||||||
|
' runs-on: ubuntu-latest',
|
||||||
|
' permissions:',
|
||||||
|
' contents: read',
|
||||||
'ref: ${{ needs.prepare-release.outputs.prepared-commit }}',
|
'ref: ${{ needs.prepare-release.outputs.prepared-commit }}',
|
||||||
'ref: ${{ needs.prepare-release.outputs.prepared-commit }}',
|
'ref: ${{ needs.prepare-release.outputs.prepared-commit }}',
|
||||||
'ref: ${{ needs.prepare-release.outputs.prepared-commit }}',
|
'ref: ${{ needs.prepare-release.outputs.prepared-commit }}',
|
||||||
@@ -66,6 +71,10 @@ describe('local release gate contract', () => {
|
|||||||
'git push origin HEAD:main',
|
'git push origin HEAD:main',
|
||||||
'git push origin HEAD:main || true'
|
'git push origin HEAD:main || true'
|
||||||
))).toThrow('stop when the automatic main push fails');
|
))).toThrow('stop when the automatic main push fails');
|
||||||
|
expect(() => validateReleaseWorkflowContract(workflow.replace(
|
||||||
|
/ permissions:\r?\n contents: read\r?\n steps:/u,
|
||||||
|
' steps:'
|
||||||
|
))).toThrow('explicitly limit GITHUB_TOKEN');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('runs the complete CI-equivalent dependency, verify, and browser sequence', () => {
|
it('runs the complete CI-equivalent dependency, verify, and browser sequence', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user