Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 43 additions & 12 deletions .github/workflows/pull-components.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ on:
workflow_dispatch:

env:
PR_BRANCH: ci/${{ github.ref_name }}
WORKING_BRANCH: ci/${{ github.ref_name }}
PR_BRANCH: pr/ci/${{ github.ref_name }}

concurrency:
# Github Actions does not support ${{ env.PR_BRANCH }} as group name...
# Github Actions does not support ${{ env.WORKING_BRANCH }} as group name...
group: ci/${{ github.ref_name }}

jobs:
Expand All @@ -22,18 +23,43 @@ jobs:
with:
path: "bottle-components-repository"
ref: ${{ github.ref_name }}
fetch-depth: 0

- name: Create or reset ${{ env.PR_BRANCH }}
- name: Create or reset ${{ env.WORKING_BRANCH }}
working-directory: "bottle-components-repository"
shell: bash {0}
run: |
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
pr_already_exists=$(gh pr list --app 'github-actions' --head ${{ env.PR_BRANCH }} --base ${{ github.ref_name }} --state 'open' --json number --jq '.[] | .[]')
if ! [ -z "$pr_already_exists" ]; then
declare -a BranchArray=( "${{ env.PR_BRANCH }}" "${{ env.WORKING_BRANCH }}" )
status=0
for BRANCH in ${BranchArray[@]}; do
git checkout $BRANCH
git rebase ${{ github.ref_name }}
status=$?
if [ $status -eq 0 ]; then
git push -f origin $BRANCH
else
break
fi
done
if [ $status -eq 0 ]; then
exit 0
fi
fi
git reset --hard ${{ github.ref_name }}
git checkout -B ${{ env.PR_BRANCH }}
git push -f --set-upstream origin ${{ env.PR_BRANCH }}
git checkout -B ${{ env.WORKING_BRANCH }}
mkdir patch_dir
touch patch_dir/.gitkeep
git add patch_dir/.gitkeep
git commit -m "Add .gitkeep file"
git push -f --set-upstream origin ${{ env.PR_BRANCH }}
git push -f --set-upstream origin ${{ env.WORKING_BRANCH }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

pull:
needs: prepare
Expand Down Expand Up @@ -272,8 +298,12 @@ jobs:
git config user.name "github-actions[bot]"
git add "${{ env.CATEGORY }}/${{ env.SUBCATEGORY }}/${{ env.NAME }}.yml" "input_files/${{ env.YAML_FILENAME }}"
git commit -m "Add ${{ env.NAME }}"
git diff HEAD~1 HEAD > patch_dir/"${{ matrix.components.order }}-${{ env.NAME }}.patch"
git reset --hard HEAD~1
file_name="${{ matrix.components.order }}-$(date -d "${{ env.CREATED_AT }}" +%s)-${{ env.NAME }}.patch"
git diff HEAD~1 HEAD > "$file_name"
git fetch origin ${{ env.WORKING_BRANCH }}:${{ env.WORKING_BRANCH }}
git switch ${{ env.WORKING_BRANCH }}
git branch --set-upstream-to=origin/${{ env.WORKING_BRANCH }} ${{ env.WORKING_BRANCH }}
mv "$file_name" patch_dir
git add patch_dir/*.patch
git pull
git commit -m "Add ${{ env.NAME }}"
Expand All @@ -293,22 +323,23 @@ jobs:
- uses: actions/checkout@v3
with:
path: "bottle-components-repository"
ref: ${{ env.PR_BRANCH }}
ref: ${{ env.WORKING_BRANCH }}
fetch-depth: 0

- name: Generate index.yml
working-directory: "bottle-components-repository"
shell: bash {0}
run: |
git checkout ${{ github.ref_name }}
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git merge ${{ env.PR_BRANCH }} --no-commit --no-ff
git merge ${{ env.WORKING_BRANCH }} --no-commit --no-ff
git reset
readarray -d '' entries < <(printf '%s\0' patch_dir/*.patch | sort -zV)
for entry in "${entries[@]}"; do
patch -p1 --fuzz 5 < "$entry"
git add -- . ':!patch_dir' ':!**.orig'
entry=${entry#patch_dir/*-}
entry=${entry#patch_dir/*-[0-9]*-}
git commit -a -m "Add component ${entry%\.patch}"
done
./generate_index.sh
Expand All @@ -320,10 +351,10 @@ jobs:
working-directory: "bottle-components-repository"
shell: bash {0}
run: |
git checkout -B pr/${{ env.PR_BRANCH }}
git push -f --set-upstream origin pr/${{ env.PR_BRANCH }}
git checkout -B ${{ env.PR_BRANCH }}
git push -f --set-upstream origin ${{ env.PR_BRANCH }}

gh_output=$(gh pr create --title "Update available :tada:" --body "One or more components have been updated!" --head pr/${{ env.PR_BRANCH }} --base ${{ github.ref_name }})
gh_output=$(gh pr create --title "Update available :tada:" --body "One or more components have been updated!" --head ${{ env.PR_BRANCH }} --base ${{ github.ref_name }})
echo "PR_CREATED=$([ $? -eq 0 ] && echo true || echo false)" >> $GITHUB_OUTPUT
pr_number=$($gh_output | tail -n1)
echo "PR_NUMBER=${pr_number#https://github.com/${{ github.repository }}/pull/}" >> $GITHUB_OUTPUT
Expand Down