-
Notifications
You must be signed in to change notification settings - Fork 34
Simplify workflow to use pull_request trigger #626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
578e90a
Simplify workflow and sort
cameron-dunn-sublime e010045
fix ref
cameron-dunn-sublime 7c643df
1 more
cameron-dunn-sublime c21f02d
head
cameron-dunn-sublime 962d8b4
Merge c21f02dc5297ca0b86ea754707b99fdb8184b422 into 00b553362873f3a92…
cameron-dunn-sublime e1c2bf9
Auto sorting static files
0757f52
Apply suggestion from @cameron-dunn-sublime
cameron-dunn-sublime File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,11 @@ | ||
| name: Ensure lists are sorted | ||
|
|
||
| on: | ||
| pull_request_target: | ||
| branches: [ "master" ] | ||
| workflow_dispatch: {} | ||
| issue_comment: | ||
| types: [ created ] | ||
| merge_group: {} | ||
| pull_request: | ||
|
|
||
| concurrency: | ||
| # For pull_request_target workflows we want to use head_ref -- the branch triggering the workflow. Otherwise, | ||
| # use ref, which is the branch for a push event or workflow trigger. And for an issue comment just give up grouping. | ||
| group: ${{ github.event_name == 'pull_request_target' && github.head_ref || (github.event_name == 'issue_comment' && github.run_id || github.ref) }} | ||
| cancel-in-progress: ${{ github.event_name == 'pull_request_target' }} | ||
| group: ${{ github.head_ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| tests: | ||
|
|
@@ -23,88 +16,26 @@ jobs: | |
| issues: read | ||
| pull-requests: read | ||
| checks: write | ||
| if: github.event_name != 'issue_comment' | ||
|
|
||
| steps: | ||
| - name: Get PR branch | ||
| if: github.event_name == 'issue_comment' | ||
| uses: alessbell/[email protected] # Fork of xt0rted/pull-request-comment-branch, see https://github.com/xt0rted/pull-request-comment-branch/issues/322 | ||
| id: comment_branch | ||
|
|
||
| - name: Get Refs | ||
| id: get_head_ref | ||
| run: | | ||
| # Accurate for push events, merge queues, and workflow dispatch. | ||
| head_ref="${{ github.ref }}" | ||
| repo="${{ github.repository }}" | ||
|
|
||
| if [[ "${{ github.event_name }}" == 'pull_request_target' ]]; then | ||
| head_ref="${{ github.head_ref }}" | ||
| repo="${{ github.event.pull_request.head.repo.full_name }}" | ||
| elif [[ "${{ github.event_name }}" == 'issue_comment' ]]; then | ||
| # Rely on comment_branch to figure out the head and base | ||
| head_ref="${{ steps.comment_branch.outputs.head_ref }}" | ||
| repo="${{ steps.comment_branch.outputs.head_owner }}/${{ steps.comment_branch.outputs.head_repo }}" | ||
| fi | ||
|
|
||
| echo "##[set-output name=head_ref;]$head_ref" | ||
| echo "##[set-output name=repo;]$repo" | ||
|
|
||
| - name: Checkout | ||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
| with: | ||
| repository: ${{ steps.get_head_ref.outputs.repo }} | ||
| ref: ${{ steps.get_head_ref.outputs.head_ref }} | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Validate Branch vs. Trigerring SHA | ||
| run: | | ||
| # If this is from a pull request validate that what we checked out is the same as the PR head. | ||
| # If not we'll just fail -- the workflow will be cancelled momentarily. | ||
| if [[ "${{ github.event_name }}" == 'pull_request_target' ]]; then | ||
| if [[ "${{ github.event.pull_request.head.sha }}" != "$(git rev-parse HEAD)" ]]; then | ||
| echo "Workflow is out of date with branch, cancelling" | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| - name: Get Refs | ||
| id: get_base_ref | ||
| run: | | ||
| run_all="" | ||
| base_ref="" | ||
|
|
||
| if [[ "${{ github.event_name }}" == 'pull_request_target' ]]; then | ||
| # Detect changes based on whatever we're merging into. | ||
| base_ref="${{ github.base_ref }}" | ||
| elif [[ "${{ github.event_name }}" == 'push' || "${{ github.event_name }}" == 'merge_group' ]]; then | ||
| # Detect changes based on the previous commit | ||
| base_ref="$(git rev-parse HEAD^)" | ||
| elif [[ "${{ github.event_name }}" == 'workflow_dispatch' ]]; then | ||
| # Run on a target | ||
| run_all="true" | ||
| elif [[ "${{ github.event_name }}" == 'issue_comment' ]]; then | ||
| # Rely on comment_branch to figure out base | ||
| base_ref="${{ steps.comment_branch.outputs.base_ref }}" | ||
| fi | ||
|
|
||
| echo "##[set-output name=run_all;]$run_all" | ||
| echo "##[set-output name=base_ref;]$base_ref" | ||
|
|
||
| - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 | ||
| with: | ||
| python-version: '3.10' | ||
|
|
||
| - name: Sort file content order | ||
| if: github.event_name != 'issue_comment' | ||
| run: | | ||
| python ./scripts/sorter.py | ||
|
|
||
| - name: Commit & Push Results, if needed | ||
| if: github.event_name != 'issue_comment' | ||
| id: final_basic_validation | ||
| id: push_results | ||
| run: | | ||
|
|
||
| echo "Using fresh workflow" | ||
|
|
||
| if [ -z "$(git status --porcelain)" ]; then | ||
| echo "No files changed, nothing to do" | ||
| exit 0 | ||
|
|
@@ -114,6 +45,4 @@ jobs: | |
| git config user.email '[email protected]' | ||
| git add '*.txt' | ||
| git commit -m "Auto sorting static files" | ||
| # This will only work when running for a pull_request_target, but rather than filter we'll let this expose | ||
| # any issues. | ||
| git push origin ${{ steps.get_head_ref.outputs.head_ref }} | ||
| git push origin HEAD:${{ github.head_ref }} | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.