GitHub repository commit #51
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
# https://github.com/skills/hello-github-actions | |
name: GitHub repository commit | |
on: | |
workflow_dispatch: | |
inputs: | |
edit: | |
description: 'to edit' | |
type: boolean | |
default: true | |
required: true | |
env: | |
BASE_BRANCH: main | |
HEAD_BRANCH: content-${{ github.run_id }} | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
commit-on-branch: | |
name: Commit a new file | |
runs-on: ubuntu-latest | |
outputs: | |
base-branch-name: ${{ steps.commit-step.outputs.base-branch-name }} | |
head-branch-name: ${{ steps.commit-step.outputs.head-branch-name }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Edit a file | |
if: inputs.edit | |
run: | | |
echo -e "\n" >> README.md | |
date >> README.md | |
- name: Prepare a branch, and file | |
id: commit-step | |
run: | | |
git checkout -b $HEAD_BRANCH | |
git config user.name github-actions[bot] | |
git config user.email 41898282+github-actions[bot]@users.noreply.github.com | |
git add . | |
git commit -m "Add date to README.md" | |
git push --set-upstream origin $HEAD_BRANCH | |
git checkout $BASE_BRANCH | |
echo "base-branch-name: $BASE_BRANCH" | |
echo "base-branch-name=$BASE_BRANCH" >> $GITHUB_OUTPUT | |
echo "head-branch-name: $HEAD_BRANCH" | |
echo "head-branch-name=$HEAD_BRANCH" >> $GITHUB_OUTPUT | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
call-pull-request-workflow: | |
name: Call pull request workflow | |
needs: commit-on-branch | |
uses: ./.github/workflows/github-pull-request-creation.yml | |
with: | |
base-branch-name: ${{ needs.commit-on-branch.outputs.base-branch-name }} | |
head-branch-name: ${{ needs.commit-on-branch.outputs.head-branch-name }} | |
show-pull-request-url: | |
name: Show pull request url | |
needs: call-pull-request-workflow | |
runs-on: ubuntu-latest | |
steps: | |
- run: echo ${{ needs.call-pull-request-workflow.outputs.pull-request-url }} |