name: Label PR version # Contributors (especially from forks) can't set labels themselves — that needs # triage rights. A PR's version line is fully determined by its base branch, so # this reads base.ref and applies v1/v2 on their behalf. pull_request_target runs # in the base repo's context so it has write access even for fork PRs; it only # reads trusted metadata (the base ref) and never checks out or runs PR code. on: pull_request_target: types: [opened, reopened, edited] permissions: pull-requests: write concurrency: group: pr-version-${{ github.event.pull_request.number }} cancel-in-progress: true jobs: label: runs-on: ubuntu-latest steps: - uses: actions/github-script@v9 with: script: | const base = context.payload.pull_request.base.ref; const label = base === 'v1' ? 'v1' : base === 'main-v2' ? 'v2' : null; if (!label) { core.info(`Base branch '${base}' isn't a release line; skipping.`); return; } const other = label === 'v2' ? 'v1' : 'v2'; await github.rest.issues.addLabels({ ...context.repo, issue_number: context.payload.pull_request.number, labels: [label], }); // Drop the other line's label if the base was changed after opening. try { await github.rest.issues.removeLabel({ ...context.repo, issue_number: context.payload.pull_request.number, name: other, }); } catch (e) { core.info(`No ${other} label to remove.`); }