-
Notifications
You must be signed in to change notification settings - Fork 863
Replace dotnet/actions-create-pull-request with local composite action #15964
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,134 @@ | ||||||||||||||||||||
| name: 'Create Pull Request' | ||||||||||||||||||||
| description: 'Creates or updates a pull request for changes to the repository' | ||||||||||||||||||||
| inputs: | ||||||||||||||||||||
| token: | ||||||||||||||||||||
| description: 'GitHub token for authentication' | ||||||||||||||||||||
| required: true | ||||||||||||||||||||
| branch: | ||||||||||||||||||||
| description: 'The pull request branch name' | ||||||||||||||||||||
| required: true | ||||||||||||||||||||
| base: | ||||||||||||||||||||
| description: 'The base branch for the pull request' | ||||||||||||||||||||
| required: false | ||||||||||||||||||||
| default: 'main' | ||||||||||||||||||||
| title: | ||||||||||||||||||||
| description: 'The title of the pull request' | ||||||||||||||||||||
| required: true | ||||||||||||||||||||
| body: | ||||||||||||||||||||
| description: 'The body of the pull request' | ||||||||||||||||||||
| required: true | ||||||||||||||||||||
| labels: | ||||||||||||||||||||
| description: 'A newline-separated list of labels' | ||||||||||||||||||||
| required: false | ||||||||||||||||||||
| default: '' | ||||||||||||||||||||
| commit-message: | ||||||||||||||||||||
| description: 'The commit message to use when committing changes' | ||||||||||||||||||||
| required: false | ||||||||||||||||||||
| default: '[create-pull-request] automated change' | ||||||||||||||||||||
| branch-already-exists: | ||||||||||||||||||||
| description: 'Set to true if the branch is already pushed remotely (skips commit/push)' | ||||||||||||||||||||
| required: false | ||||||||||||||||||||
| default: 'false' | ||||||||||||||||||||
| outputs: | ||||||||||||||||||||
| pull-request-number: | ||||||||||||||||||||
| description: 'The pull request number' | ||||||||||||||||||||
| value: ${{ steps.create-pr.outputs.pull-request-number }} | ||||||||||||||||||||
| pull-request-url: | ||||||||||||||||||||
| description: 'The URL of the pull request' | ||||||||||||||||||||
| value: ${{ steps.create-pr.outputs.pull-request-url }} | ||||||||||||||||||||
| pull-request-operation: | ||||||||||||||||||||
| description: 'The pull request operation performed (created, updated, none)' | ||||||||||||||||||||
| value: ${{ steps.create-pr.outputs.pull-request-operation }} | ||||||||||||||||||||
| runs: | ||||||||||||||||||||
| using: 'composite' | ||||||||||||||||||||
| steps: | ||||||||||||||||||||
| - name: Configure git authentication | ||||||||||||||||||||
| shell: bash | ||||||||||||||||||||
| env: | ||||||||||||||||||||
| GH_TOKEN: ${{ inputs.token }} | ||||||||||||||||||||
| run: | | ||||||||||||||||||||
| # Use the provided token for both git and gh operations | ||||||||||||||||||||
| gh auth setup-git | ||||||||||||||||||||
|
|
||||||||||||||||||||
| - name: Commit and push changes | ||||||||||||||||||||
| if: inputs.branch-already-exists != 'true' | ||||||||||||||||||||
| id: commit-and-push | ||||||||||||||||||||
| shell: bash | ||||||||||||||||||||
| env: | ||||||||||||||||||||
| BRANCH: ${{ inputs.branch }} | ||||||||||||||||||||
| COMMIT_MESSAGE: ${{ inputs.commit-message }} | ||||||||||||||||||||
| run: | | ||||||||||||||||||||
| # Check for any changes (staged, unstaged, or untracked) | ||||||||||||||||||||
| if git diff --quiet && git diff --cached --quiet && [ -z "$(git ls-files --others --exclude-standard)" ]; then | ||||||||||||||||||||
| echo "No changes to commit" | ||||||||||||||||||||
| echo "has_changes=false" >> $GITHUB_OUTPUT | ||||||||||||||||||||
| exit 0 | ||||||||||||||||||||
| fi | ||||||||||||||||||||
|
|
||||||||||||||||||||
| echo "has_changes=true" >> $GITHUB_OUTPUT | ||||||||||||||||||||
|
|
||||||||||||||||||||
| git config user.name "github-actions[bot]" | ||||||||||||||||||||
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Create or reset branch | ||||||||||||||||||||
| git checkout -B "$BRANCH" | ||||||||||||||||||||
| git add -A | ||||||||||||||||||||
| git commit -m "$COMMIT_MESSAGE" | ||||||||||||||||||||
| git push -f origin "$BRANCH" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| - name: Create or update pull request | ||||||||||||||||||||
| id: create-pr | ||||||||||||||||||||
| if: inputs.branch-already-exists == 'true' || steps.commit-and-push.outputs.has_changes == 'true' | ||||||||||||||||||||
| shell: bash | ||||||||||||||||||||
| env: | ||||||||||||||||||||
| GH_TOKEN: ${{ inputs.token }} | ||||||||||||||||||||
| BRANCH: ${{ inputs.branch }} | ||||||||||||||||||||
| BASE: ${{ inputs.base }} | ||||||||||||||||||||
| PR_TITLE: ${{ inputs.title }} | ||||||||||||||||||||
| PR_BODY: ${{ inputs.body }} | ||||||||||||||||||||
| LABELS: ${{ inputs.labels }} | ||||||||||||||||||||
| run: | | ||||||||||||||||||||
| # Check if a PR already exists for this branch | ||||||||||||||||||||
| EXISTING_PR=$(gh pr list --head "$BRANCH" --base "$BASE" --json number,url --jq '.[0] // empty') | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if [ -n "$EXISTING_PR" ]; then | ||||||||||||||||||||
| PR_NUMBER=$(echo "$EXISTING_PR" | jq -r '.number') | ||||||||||||||||||||
| PR_URL=$(echo "$EXISTING_PR" | jq -r '.url') | ||||||||||||||||||||
|
Comment on lines
+92
to
+96
|
||||||||||||||||||||
| EXISTING_PR=$(gh pr list --head "$BRANCH" --base "$BASE" --json number,url --jq '.[0] // empty') | |
| if [ -n "$EXISTING_PR" ]; then | |
| PR_NUMBER=$(echo "$EXISTING_PR" | jq -r '.number') | |
| PR_URL=$(echo "$EXISTING_PR" | jq -r '.url') | |
| PR_NUMBER=$(gh pr list --head "$BRANCH" --base "$BASE" --json number --jq '.[0].number // empty') | |
| if [ -n "$PR_NUMBER" ]; then | |
| PR_URL=$(gh pr list --head "$BRANCH" --base "$BASE" --json url --jq '.[0].url // empty') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't fix. jq is pre-installed on all GitHub-hosted runners (ubuntu-latest, windows-latest, macos-latest) and is already used extensively in other steps of release-github-tasks.yml. The extra gh pr list call suggested would double the API requests for the existing-PR path. Not worth the churn for a non-issue.
Uh oh!
There was an error while loading. Please reload this page.