Skip to content

Commit

Permalink
fix: Skip package if the last commit is after the comment
Browse files Browse the repository at this point in the history
  • Loading branch information
yanguoyu committed Jun 12, 2024
1 parent aa100d7 commit b0a745b
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions .github/workflows/package_for_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,52 @@ on:
push:

jobs:
check_issue_comment:
if: ${{ (github.event_name == 'issue_comment' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/package') && contains(fromJSON('["OWNER", "COLLABORATOR"]'), github.event.comment.author_association)) }}

runs-on: ubuntu-20.04

steps:
- name: Check without commit after comment
uses: actions/github-script@v7
env:
ISSUE_NUMBER: ${{github.event.issue.number}}
COMMENT_ID: ${{ github.event.comment.id }}
with:
script: |
const { ISSUE_NUMBER, COMMENT_ID } = process.env
let page = 1
let hasFoundComment = false
while(true) {
const { data: timelines } = await github.rest.issues.listEventsForTimeline({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ISSUE_NUMBER,
page,
per_page: 100,
})
if (timelines.find(v => {
hasFoundComment = hasFoundComment || (v.event === 'commented' && `${v.id}` === `${COMMENT_ID}`)
return hasFoundComment && v.event === 'committed'
})) {
throw new Error('The last commit comes after the comment, please comment and package after last commit')
}
if (timelines.length === 0) {
return
}
page += 1
}
packaging:
if: ${{ (github.event_name == 'issue_comment' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/package') && contains(fromJSON('["OWNER", "COLLABORATOR"]'), github.event.comment.author_association)) || github.event_name == 'push' }}
needs: [check_issue_comment]
if: ${{ (always() && needs.check_issue_comment.result == 'skipped' && github.event_name == 'push') || success() }}

strategy:
matrix:
node:
- 18.12.0
os:
- macos-latest
- ubuntu-20.04
- windows-2019

runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -45,6 +80,16 @@ jobs:
if: ${{ github.event_name == 'issue_comment' }}
with:
ref: refs/pull/${{ github.event.issue.number }}/merge

- name: Echo
run: |
echo "$COMMENT_UPDATE_AT"
echo "$ISSUE_UPDATE_AT"
echo "$TIMELINE"
env:
COMMENT_UPDATE_AT: ${{ github.event.comment.updated_at }}
ISSUE_UPDATE_AT: ${{ github.event.issue.updated_at }}
TIMELINE: ${{ github.event.issue.timeline_url }}

- name: Setup Node
uses: actions/setup-node@v4
Expand Down

0 comments on commit b0a745b

Please sign in to comment.