π FF Merge #9
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
name: fast-forward-merger | |
run-name: 'π FF Merge' | |
on: | |
issue_comment: | |
types: | |
- created | |
permissions: | |
contents: read | |
jobs: | |
comment_checks: | |
name: Check FF-Merge Conditions | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
issues: read | |
outputs: | |
valid_commenter: ${{ steps.ff_merge_check_valid_commenter.outputs.valid_commenter }} | |
valid_comment: ${{ steps.ff_merge_check_comment_content.outputs.valid_comment }} | |
valid_label: ${{ steps.ff_merge_check_issue_labels.outputs.valid_label }} | |
steps: | |
- name: Debug Event | |
uses: actions/[email protected] | |
with: | |
script: | | |
console.log("%O", `${{ github.event }}`); | |
console.log("GH_CTX_EVENT:", `${{ github.event }}`); | |
console.log("GH_CTX_ISSUE_COMMENT:", ${{ github.event.pull_request }}); | |
console.log("GS_CTX_PAYLOAD :", context.payload); | |
- name: Check Comment Author π΅οΈ | |
id: ff_merge_check_valid_commenter | |
uses: actions/[email protected] | |
with: | |
script: | | |
const commentAuthorAssociation = context.payload.comment.author_association; | |
const isMember = commentAuthorAssociation === 'MEMBER'; | |
if (isMember) { | |
core.info('β The comment author is a member of the organization.'); | |
} else { | |
core.warning('β The comment author is not a member of the organization.'); | |
} | |
core.debug('COMMENT_AUTHOR:', commentAuthorAssociation); | |
core.setOutput('valid_commenter', isMember); | |
- name: Check Comment Content π | |
id: ff_merge_check_comment_content | |
if: ${{ steps.ff_merge_check_valid_commenter.outputs.valid_commenter }} | |
uses: actions/[email protected] | |
with: | |
script: | | |
const commentBody = context.payload.comment.body; | |
const isValidComment = commentBody === '/ff-merge'; | |
if (isValidComment) { | |
core.info('β The comment content is valid.'); | |
} else { | |
core.warning('β The comment content is invalid. (Expected: /ff-merge)'); | |
} | |
core.debug('COMMENT_BODY:', commentBody); | |
core.setOutput('valid_comment', isValidComment); | |
- name: Check Issue Labels π·οΈ | |
id: ff_merge_check_issue_labels | |
if: ${{ steps.ff_merge_check_comment_content.outputs.valid_comment }} | |
uses: actions/[email protected] | |
with: | |
script: | | |
const issueLabels = context.payload.issue.labels; | |
const hasFFMergeLabel = issueLabels.some((label) => label.name === 'ff-merge'); | |
if (hasFFMergeLabel) { | |
core.info('β The issue has the "ff-merge" label.'); | |
} else { | |
core.warning('β The issue does not have the "ff-merge" label.'); | |
} | |
core.debug('ISSUE_LABELS:', issueLabels.map((label) => label.name)); | |
core.setOutput('valid_label', hasFFMergeLabel); | |
exec_ff_merge: | |
name: Execute Fast-Forward Merge | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
needs: comment_checks | |
if: ${{ needs.comment_checks.outputs.valid_commenter == 'true' && needs.comment_checks.outputs.valid_comment == 'true' && needs.comment_checks.outputs.valid_label == 'true' }} | |
steps: | |
- name: Lock PR π | |
id: lock_pr | |
uses: actions/[email protected] | |
with: | |
script: | | |
try { | |
await github.rest.issues.lock({ | |
'owner': context.repo.owner, | |
'repo': context.repo.repo, | |
'issue_number': context.issue.number, | |
'lock_reason': 'resolved', | |
}); | |
console.info('PR locked:', context.payload.issue.html_url); | |
} catch (err) { | |
console.error('Error locking PR:', err); | |
core.setFailed(`Action failed with error ${err}`); | |
} | |
- name: Fast-Forward Merge π | |
if: ${{ success() }} | |
run: | | |
echo "β Fast-Forward Merge completed." | |
echo "BASE_REF: ${{ github.base_ref }}" | |
echo "HEAD_REF: ${{ github.event.pull_request.head.ref }}" |