8000 Fix directory workflow script (#25) · TheAlgorithms/scripts@e919180 · GitHub
[go: up one dir, main page]

Skip to content

Commit e919180

Browse files
authored
Fix directory workflow script (#25)
* Fix directory workflow script * Let the user choose the branch name
1 parent 124f337 commit e919180

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

.github/workflows/directory-ignore-files.yml

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ jobs:
1515
working-directory: .
1616
filetypes: .cpp,.hpp
1717
ignored-directories: ./test
18+
branch-name: directory-update-ignore

.github/workflows/directory.yml

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ jobs:
1414
language: scripts
1515
working-directory: ./test
1616
filetypes: .cpp,.hpp
17+
branch-name: directory-update

directory_md/action.yml

+24-9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ inputs:
1818
ignore-folders-children:
1919
description: Folders to ignore, but include children.
2020
required: false
21+
branch-name:
22+
description: The branch that will be used to push changes.
23+
required: false
24+
default: directory-update
2125
runs:
2226
using: composite
2327
steps:
@@ -35,18 +39,29 @@ runs:
3539
- name: Running the directory builder
3640
shell: bash
3741
run: |
42+
# If branch exists, change to that branch to prevent multiple committing/PR creation.
43+
git checkout ${{ inputs.branch-name }} || true
44+
3845
python build_directory_md.py ${{ inputs.language }} ${{ inputs.working-directory }} ${{ inputs.filetypes }} ${{ inputs.ignored-directories }} ${{ inputs.ignore-folders-children }} > DIRECTORY.md
39-
- name: Committing changes
46+
- name: Creating a branch
4047
shell: bash
4148
run: |
42-
git branch directory-update
43-
git checkout directory-update
49+
git branch ${{ inputs.branch-name }} || true
50+
git checkout ${{ inputs.branch-name }} || true
4451
45-
git commit -m "docs: update `DIRECTORY.md`" DIRECTORY.md || true
46-
git push origin directory-update:directory-update --force
47-
- name: Creating a pull request
52+
- name: Committing, pushing, and creating a PR
4853
shell: bash
4954
run: |
50-
if [[ `git status --porcelain` ]]; then
51-
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
52-
# `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.
55+
if [[ `git status --porcelain` ]];
56+
then
57+
58+
git add DIRECTORY.md
59+
60+
git commit -m "docs: update DIRECTORY.md" || true
61+
git push origin ${{ inputs.branch-name }}:${{ inputs.branch-name }} --force
62+
63+
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
64+
# Using `true` will make sure no errors are displayed even if there's a PR created.
65+
fi
66+
env:
67+
GH_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)
0