Skip to content

Initial commit

Initial commit #1

name: Sync Template files to repositories
on: # rebuild any PRs and main branch changes
push:
branches:
- main
workflow_call:
secrets:
REPOS_ACCESS_TOKEN:
required: true
jobs:
# Run cleaning process only if workflow is triggered by the non-ERNI-Academy/erni-academy-template repository.
template-cleanup:
name: Template Cleanup
runs-on: ubuntu-latest
if: github.event.repository.name != 'erni-academy-template'
steps:
# Check out current repository
- name: Checkout
uses: actions/checkout@v3
# Cleanup project
- name: Cleanup
run: |
# Cleanup
rm -rf \
sync.yml \
.github/workflows/SyncTemplateWithRepos.yml \
# Commit modified files
- name: Commit files
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git commit -m "🗑️ Template cleanup"
# Push changes
- name: Push changes
uses: ad-m/github-push-action@master
with:
branch: main
github_token: ${{ secrets.GITHUB_TOKEN }}
generate_list_of_repos:
if: github.event.repository.name == 'erni-academy-template'
runs-on: ubuntu-latest
outputs:
repos: ${{ steps.generate-matrix.outputs.repos}}
matrix: ${{ steps.generate-matrix.outputs.matrix}}
steps:
- name: Generate Matrix
id: generate-matrix
run: |
REPOSITORIES=`curl https://api.github.com/orgs/ERNI-Academy/repos?per_page=200 -H "Accept: application/json" -H "Bearer ${{ secrets.REPOS_ACCESS_TOKEN }}" | jq '.[].name'`
echo $REPOSITORIES
REPOSITORIES_FOR_JSON=`echo $REPOSITORIES | sed 's/ /},{\"repo\":/g'`
echo $REPOSITORIES_FOR_JSON
REPOSITORIES_FOR_JSON="{\"include\":[{\"repo\":$REPOSITORIES_FOR_JSON}]}"
echo $REPOSITORIES_FOR_JSON
REPOSITORIES_FOR_JSON="{\"include\":[{\"repo\":\"Test_Sync_Repo\"}]}"
echo ::set-output name=matrix::$JSON_REPOS
REPOSITORIES=`echo $REPOSITORIES | sed 's/\".github\" //g'`
REPOSITORIES_FOR_LIST=`echo $REPOSITORIES | sed 's/\" \"/\n ERNI-Academy\//g'`
REPOSITORIES_FOR_LIST=`echo $REPOSITORIES_FOR_LIST | sed 's/\"//g'`
REPOSITORIES_FOR_LIST="ERNI-Academy/$REPOSITORIES_FOR_LIST"
REPOSITORIES_FOR_LIST="\"$REPOSITORIES_FOR_LIST\""
echo $REPOSITORIES_FOR_LIST
echo ::set-output name=repos::$REPOSITORIES_FOR_LIST
shell: bash
propagate_changes_to_repos:
if: github.event.repository.name == 'erni-academy-template'
needs: generate_list_of_repos
runs-on: ubuntu-latest
steps:
- run: echo ${{ matrix.repo }}
- name: Checkout
uses: actions/checkout@v3
- name: Create Configuration File
id: create_configuration_file
shell: bash
run: |
echo ${{ needs.generate_list_of_repos.outputs.repos }}
value=$(<sync.yml)
echo "START newstr and oldstr value"
oldstr="Repositories"
newstr="\n ERNI-Academy\/Test_Sync_Repo"
newstr=$(echo ${{ needs.generate_list_of_repos.outputs.repos }})
echo "END newstr and oldstr value"
echo "START newString value"
echo "${newstr}"
echo "END newString value"
for i in ${newstr}; do echo " $i" >> sync.yml; done
# sed -i "s/Repositories/${newstr}/g" sync.yml
value_new=$(<sync.yml)
echo "$value_new"
- uses: BetaHuhn/repo-file-sync-action@latest
with:
GH_PAT: ${{ secrets.REPOS_ACCESS_TOKEN}}
CONFIG_PATH: sync.yml
PR_LABELS: |
file-sync
automerge
template-sync