From 891811c9c0b98bda0d08302a9a62a853edb69510 Mon Sep 17 00:00:00 2001 From: David Leal Date: Wed, 14 Jun 2023 08:36:53 -0600 Subject: [PATCH 1/2] Fix directory workflow script --- directory_md/action.yml | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/directory_md/action.yml b/directory_md/action.yml index 19a007c..8f02345 100644 --- a/directory_md/action.yml +++ b/directory_md/action.yml @@ -35,18 +35,29 @@ runs: - name: Running the directory builder shell: bash run: | + # If branch exists, change to that branch to prevent multiple committing/PR creation. + git checkout directory-update || true + python build_directory_md.py ${{ inputs.language }} ${{ inputs.working-directory }} ${{ inputs.filetypes }} ${{ inputs.ignored-directories }} ${{ inputs.ignore-folders-children }} > DIRECTORY.md - - name: Committing changes + - name: Creating a branch shell: bash run: | - git branch directory-update - git checkout directory-update + git branch directory-update || true + git checkout directory-update || true - git commit -m "docs: update `DIRECTORY.md`" DIRECTORY.md || true - git push origin directory-update:directory-update --force - - name: Creating a pull request + - name: Committing, pushing, and creating a PR shell: bash run: | - if [[ `git status --porcelain` ]]; then + if [[ `git status --porcelain` ]]; + then + + git add DIRECTORY.md + + git commit -m "docs: update DIRECTORY.md" || true + git push origin directory-update:directory-update --force + gh pr create --base ${GITHUB_REF##*/} --head directory-update --title 'docs: updating `DIRECTORY.md`' --body 'Updated the `DIRECTORY.md` file (see the diff. for changes).' || true - # `true` is needed in case the PR has been already created to prevent the CI to fail. The changes will already be pushed to the current PR's branch. + # Using `true` will make sure no errors are displayed even if there's a PR created. + fi + env: + GH_TOKEN: ${{ github.token }} From 5e2dc5fdc5f63e8ad01352df98fc9b823360644f Mon Sep 17 00:00:00 2001 From: David Leal Date: Wed, 14 Jun 2023 14:56:21 +0000 Subject: [PATCH 2/2] Let the user choose the branch name --- .github/workflows/directory-ignore-files.yml | 1 + .github/workflows/directory.yml | 1 + directory_md/action.yml | 14 +++++++++----- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/directory-ignore-files.yml b/.github/workflows/directory-ignore-files.yml index 58a93c7..7d391ab 100644 --- a/.github/workflows/directory-ignore-files.yml +++ b/.github/workflows/directory-ignore-files.yml @@ -15,3 +15,4 @@ jobs: working-directory: . filetypes: .cpp,.hpp ignored-directories: ./test + branch-name: directory-update-ignore diff --git a/.github/workflows/directory.yml b/.github/workflows/directory.yml index 97e2361..9cf385b 100644 --- a/.github/workflows/directory.yml +++ b/.github/workflows/directory.yml @@ -14,3 +14,4 @@ jobs: language: scripts working-directory: ./test filetypes: .cpp,.hpp + branch-name: directory-update diff --git a/directory_md/action.yml b/directory_md/action.yml index 8f02345..284a0c2 100644 --- a/directory_md/action.yml +++ b/directory_md/action.yml @@ -18,6 +18,10 @@ inputs: ignore-folders-children: description: Folders to ignore, but include children. required: false + branch-name: + description: The branch that will be used to push changes. + required: false + default: directory-update runs: using: composite steps: @@ -36,14 +40,14 @@ runs: shell: bash run: | # If branch exists, change to that branch to prevent multiple committing/PR creation. - git checkout directory-update || true + git checkout ${{ inputs.branch-name }} || true python build_directory_md.py ${{ inputs.language }} ${{ inputs.working-directory }} ${{ inputs.filetypes }} ${{ inputs.ignored-directories }} ${{ inputs.ignore-folders-children }} > DIRECTORY.md - name: Creating a branch shell: bash run: | - git branch directory-update || true - git checkout directory-update || true + git branch ${{ inputs.branch-name }} || true + git checkout ${{ inputs.branch-name }} || true - name: Committing, pushing, and creating a PR shell: bash @@ -54,9 +58,9 @@ runs: git add DIRECTORY.md git commit -m "docs: update DIRECTORY.md" || true - git push origin directory-update:directory-update --force + git push origin ${{ inputs.branch-name }}:${{ inputs.branch-name }} --force - gh pr create --base ${GITHUB_REF##*/} --head directory-update --title 'docs: updating `DIRECTORY.md`' --body 'Updated the `DIRECTORY.md` file (see the diff. for changes).' || true + gh pr create --base ${GITHUB_REF##*/} --head ${{ inputs.branch-name }} --title 'docs: updating `DIRECTORY.md`' --body 'Updated the `DIRECTORY.md` file (see the diff. for changes).' || true # Using `true` will make sure no errors are displayed even if there's a PR created. fi env: