Merge changes to all target branches #61
Workflow file for this run
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
name: Merge changes to all target branches | |
on: workflow_dispatch | |
jobs: | |
get_avatar_branches: | |
name: Get avatar branches | |
uses: ./.github/workflows/get_target_branches.yml | |
with: | |
include_base: true | |
check: | |
name: Check if the specified branch is not avatar branch | |
needs: get_avatar_branches | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4.1.1 | |
with: | |
fetch-depth: 0 | |
- name: Check if the specified branch is not avatar branch | |
id: check_2 | |
run: echo is_avatar_branch=$(echo ${TARGET_BRANCHES} | jq "contains([\"${BRANCH_NAME}\"])") >> $GITHUB_OUTPUT | |
env: | |
TARGET_BRANCHES: ${{ needs.get_avatar_branches.outputs.target_branches }} | |
BRANCH_NAME: ${{ github.ref_name }} | |
- name: Output error | |
if: ${{ steps.check_2.outputs.is_avatar_branch == 'true' }} | |
run: | | |
echo "::error::Cannot specify an avatar branch as a merge branch." | |
exit 1 | |
merge_branch: | |
name: Merge branch to avatar branches | |
needs: | |
- get_avatar_branches | |
- check | |
if: ${{ needs.check.result == 'success' }} | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
strategy: | |
matrix: | |
target_branch: ${{ fromJSON(needs.get_avatar_branches.outputs.target_branches) }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4.1.1 | |
with: | |
fetch-depth: 0 | |
ref: ${{ matrix.target_branch }} | |
- name: Configure Git user | |
run: | | |
git remote set-url origin https://github-actions:${TOKEN}@github.com/${REPOSITORY} | |
git config user.name github-actions[bot] | |
git config user.email github-actions[bot]@users.noreply.github.com | |
env: | |
TOKEN: ${{ github.token }} | |
REPOSITORY: ${{ github.repository }} | |
- name: Check if readme templates have been changed (base) | |
id: check_readme_changes_base | |
if: ${{ matrix.target_branch == 'base' }} | |
run: git diff --name-only origin/${MERGE_BRANCH} | grep -e '.github/README_templates/' -e '.github/readme_generator/' -e '.github/workflows/' | |
env: | |
MERGE_BRANCH: ${{ github.ref_name }} | |
continue-on-error: true | |
- name: Merge branch | |
id: merge_branch | |
run: git merge origin/${BRANCH_NAME} | |
env: | |
BRANCH_NAME: ${{ github.ref_name }} | |
continue-on-error: true | |
- name: Output error | |
if: ${{ steps.merge_branch.outcome == 'failure' }} | |
run: echo "::error::Failed to merge \"${MERGE_BRANCH}\" to \"${BASE_BRANCH}\" because of merge conflicts. You need to resolve conflicts manually." | |
env: | |
MERGE_BRANCH: ${{ github.ref_name }} | |
BASE_BRANCH: ${{ matrix.target_branch }} | |
- name: Push changes | |
if: ${{ steps.merge_branch.outcome == 'success' }} | |
run: git push origin | |
- name: Check if readme templates have been changed | |
id: check_readme_changes | |
if: ${{ steps.merge_branch.outcome == 'success' }} | |
run: | | |
if [ ${BASE_BRANCH} = 'base' ]; then | |
echo ${BASE_RESULT} | grep 'success' | |
else | |
git diff --name-only HEAD~ | grep -e '.github/README_templates/' -e '.github/readme_generator/' -e '.github/workflows/' | |
fi | |
env: | |
BASE_RESULT: ${{ steps.check_readme_changes_base.outcome }} | |
BASE_BRANCH: ${{ matrix.target_branch }} | |
continue-on-error: true | |
- name: Output readme status | |
if: ${{ steps.merge_branch.outcome == 'success' && steps.check_readme_changes.outcome == 'success' }} | |
run: | | |
echo '{"generate_required": true}' > ./${BRANCH_NAME}.json | |
env: | |
BRANCH_NAME: ${{ matrix.target_branch }} | |
- name: Output readme status | |
if: ${{ steps.merge_branch.outcome != 'success' || steps.check_readme_changes.outcome != 'success' }} | |
run: | | |
echo '{"generate_required": false}' > ./${BRANCH_NAME}.json | |
env: | |
BRANCH_NAME: ${{ matrix.target_branch }} | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4.3.3 | |
with: | |
name: ${{ matrix.target_branch }} | |
path: ./${{ matrix.target_branch }}.json | |
retention-days: 1 | |
get_readme_array: | |
name: Get array of branches that are required to generate readme | |
needs: merge_branch | |
runs-on: ubuntu-latest | |
outputs: | |
branch_array: ${{ steps.output_branch_array.outputs.branch_array }} | |
branch_count: ${{ steps.output_branch_array.outputs.branch_count }} | |
steps: | |
- name: Prepare artifacts directory | |
run: mkdir ./branches | |
- name: Download artifacts | |
uses: actions/download-artifact@v4.1.7 | |
with: | |
path: ./branches | |
- name: Get generate readme branch array | |
run: | | |
echo -n '[' > ./readme_array.json | |
for file in $(ls ./branches); do | |
result=$(cat ./branches/${file}/${file}.json | jq '.generate_required') | |
if [ ${result} = 'true' ]; then | |
echo "\"${file}\", " | sed -z 's/.json//g; s/\r//g; s/\n//g' >> ./readme_array.json | |
fi | |
done | |
echo $(cat ./readme_array.json | sed 's/, $//g')] > ./readme_array.json | |
- name: Output generate readme branch array | |
id: output_branch_array | |
run: | | |
echo branch_array=$(<./readme_array.json) >> $GITHUB_OUTPUT | |
echo branch_count=$(cat ./readme_array.json | jq length) >> $GITHUB_OUTPUT | |
generate_readme: | |
name: Generate readme | |
needs: get_readme_array | |
if: ${{ needs.get_readme_array.outputs.branch_count > 0 }} | |
permissions: | |
contents: write | |
strategy: | |
matrix: | |
target_branch: ${{ fromJSON(needs.get_readme_array.outputs.branch_array) }} | |
uses: ./.github/workflows/generate_readme_core.yml | |
with: | |
branch-name: ${{ matrix.target_branch }} |