Skip to content

[ticket-062] fix(versioning): read setup() version literals #48

[ticket-062] fix(versioning): read setup() version literals

[ticket-062] fix(versioning): read setup() version literals #48

name: new-project-governance
on:
pull_request:
types: [opened, synchronize, reopened, closed]
schedule:
- cron: "17 3 * * *"
workflow_dispatch:
permissions:
contents: read
pull-requests: read
jobs:
remote-lifecycle:
name: governance / remote lifecycle
runs-on: ubuntu-latest
steps:
- name: Check out governed repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Acquire GitHub branch lifecycle snapshot
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
BRANCH_LIFECYCLE_SNAPSHOT: ${{ runner.temp }}/new-project-branch-lifecycle.json
with:
script: |
const fs = require('fs');
const repository = await github.rest.repos.get({
owner: context.repo.owner,
repo: context.repo.repo,
});
const settings = await github.graphql(`
query($owner: String!, $repo: String!) {
repository(owner: $owner, name: $repo) { deleteBranchOnMerge }
}
`, {owner: context.repo.owner, repo: context.repo.repo});
const branches = await github.paginate(github.rest.repos.listBranches, {
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100,
});
const pulls = await github.paginate(github.rest.pulls.list, {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
per_page: 100,
});
const snapshot = {
schema: 'new-project.branch-lifecycle-snapshot/v1',
repository: `${context.repo.owner}/${context.repo.repo}`,
defaultBranch: repository.data.default_branch,
deleteBranchOnMerge: settings.repository.deleteBranchOnMerge,
branches: branches.map(branch => branch.name).sort(),
openPullRequests: pulls.map(pull => ({
number: pull.number,
headRepository: pull.head.repo?.full_name ?? null,
headRef: pull.head.ref,
})).sort((left, right) => left.number - right.number),
};
fs.writeFileSync(
process.env.BRANCH_LIFECYCLE_SNAPSHOT,
`${JSON.stringify(snapshot)}\n`,
{encoding: 'utf8', mode: 0o600},
);
- name: Validate remote branch lifecycle
shell: bash
env:
BRANCH_LIFECYCLE_SNAPSHOT: ${{ runner.temp }}/new-project-branch-lifecycle.json
run: |
python3 .governance/branch_lifecycle_check.py \
--snapshot "$BRANCH_LIFECYCLE_SNAPSHOT" \
--expected-repository "$GITHUB_REPOSITORY" \
--format text