Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tangrufus committed Dec 11, 2024
1 parent 4a83b15 commit 8439489
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 19 deletions.
25 changes: 6 additions & 19 deletions .github/actions/create-auto-merged-pull-request/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ inputs:
default: bot

# secrets
pr-write-pat-token:
app-id:
description: The PAT token that the action will use to reopen the pull request.
default: ${{ vars.TASTENDRUCK_APP_ID }}
required: true
token:
private-key:
description: The token that the action will use to create, update and close the pull request.
default: ${{ secrets.TASTENDRUCK_PRIVATE_KEY }}
required: true

outputs:
Expand Down Expand Up @@ -82,6 +84,7 @@ runs:
id: create-pull-request
uses: peter-evans/create-pull-request@v7
with:
token: ${{ steps.app-token.outputs.token }}
add-paths: ${{ inputs.add-paths }}
commit-message: | # The blank line is important.
${{ inputs.title }}
Expand All @@ -95,26 +98,10 @@ runs:
body: ${{ steps.tmp-vars.outputs.body }}
labels: ${{ inputs.labels }}

- name: Close the PR
if: steps.create-pull-request.outputs.pull-request-operation == 'created' || steps.create-pull-request.outputs.pull-request-operation == 'updated'
run: gh pr close "$PR_URL"
shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
PR_URL: ${{ steps.create-pull-request.outputs.pull-request-url }}

- name: Reopen the PR with PAT token
if: steps.create-pull-request.outputs.pull-request-operation == 'created' || steps.create-pull-request.outputs.pull-request-operation == 'updated'
run: gh pr reopen "$PR_URL"
shell: bash
env:
GH_TOKEN: ${{ inputs.pr-write-pat-token }}
PR_URL: ${{ steps.create-pull-request.outputs.pull-request-url }}

- name: Enable auto-merge for the PR
if: steps.create-pull-request.outputs.pull-request-operation == 'created' || steps.create-pull-request.outputs.pull-request-operation == 'updated'
run: gh pr merge --auto --squash "$PR_URL"
shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
GH_TOKEN: ${{ steps.app-token.outputs.token }}
PR_URL: ${{ steps.create-pull-request.outputs.pull-request-url }}
98 changes: 98 additions & 0 deletions .github/workflows/create-auto-merged-pull-request-php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Create Auto-merged Pull Request

on:
workflow_call:
inputs:
command:
description: The command to create the actual changeset
required: true
type: string

# shivammathur/setup-php
php-version:
description: Setup PHP version.
default: '8.4'
type: string

# ramsey/composer-install
dependency-versions:
description: The version of dependencies to prefer (`lowest`, `highest`, or `locked`).
default: locked
type: string
composer-options:
description: Additional options to pass to Composer (e.g. `--ignore-platform-reqs`).
default: --optimize-autoloader
type: string

# create-auto-merged-pull-request
add-paths:
description: >
A comma or newline-separated list of file paths to commit.
Paths should follow git's pathspec syntax.
Defaults to adding all new and modified files.
type: string
branch:
description: The pull request branch name.
required: true
type: string
delete-branch:
description: >
Delete the `branch` if it doesn't have an active pull request associated with it.
default: true
type: boolean
base:
description: >
The pull request base branch.
Defaults to the branch checked out in the workflow.
default: ${{ github.ref_name }}
type: string
title:
description: The title of the pull request.
type: string
body:
description: The body of the pull request.
type: string
labels:
description: A comma or newline separated list of labels.
type: string

permissions: {}

jobs:
create-auto-merged-pull-request-php:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php-version }}
coverage: none
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: ramsey/composer-install@v3
with:
dependency-versions: ${{ inputs.dependency-versions }}
composer-options: ${{ inputs.composer-options }}

- run: ${{ inputs.command }}

- name: Compute temporary variables
id: tmp-vars
shell: bash
run: |
echo "title=:robot: \`$COMMAND\`" >> "$GITHUB_OUTPUT"
env:
COMMAND: ${{ inputs.command }}

- uses: typisttech/.github/.github/workflows/create-auto-merged-pull-request@app-token
with:
add-paths: ${{ inputs.add-paths }}
branch: ${{ inputs.branch }}
delete-branch: ${{ inputs.delete-branch }}
base: ${{ inputs.base }}
title: ${{ inputs.title || steps.tmp-vars.outputs.title }}
labels: ${{ inputs.labels }}

0 comments on commit 8439489

Please sign in to comment.