Skip to content

Add examples & publish starter workflows on push #4

Add examples & publish starter workflows on push

Add examples & publish starter workflows on push #4

name: Update starter workflows
on:
push:
branches: [trunk]
pull_request:
branches: [trunk]
jobs:
update-starter-workflows:
name: Update starter workflows
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
path: ${{ github.repository }}
- name: Checkout .github repository
uses: actions/checkout@v4
with:
repository: '3lvia/.github'
path: 'dotgithub'
- name: Get GitHub App token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
- name: Update workflows-templates
shell: bash
run: |
for workflow_path in $(find ${GITHUB_REPOSITORY#*/}/.github/workflows/example-* -type f); do
file_name="$(basename $workflow_path)"
new_workflow_path="dotgithub/workflow-templates/${file_name#*-}"
cp "$workflow_path" "$new_workflow_path"
sed -i "s/APPLICATION_NAME: 'demo-api'/APPLICATION_NAME: '<your application name here>'/g" "$new_workflow_path"
sed -i "s/SYSTEM_NAMESPACE: 'core'/SYSTEM_NAMESPACE: '<your system namespace here>'/"
sed -i "s/helm-values-path: '.github\/test\/deploy\/values.yaml'/helm-values-path: '<your Helm values path here>'/g" "$new_workflow_path"
workflow_properties_file="dotgithub/workflow-templates/${file_name%.*}.properties.json"
if [ ! -f "$workflow_properties_file" ]; then
workflow_name=$(cat "$new_workflow_path" | yq '.name')
workflow_description=$(cat "$new_workflow_path" | yq '.description')
cat << EOF > "$workflow_properties_file"
{
"name": $workflow_name,
"description": $workflow_description
}
EOF
fi
done
- name: Commit changes
shell: bash
run: |
cd dotgithub
if [[ -z "$(git status --porcelain)" ]]; then
echo 'No changes to commit.'
exit 0
fi
git config user.name github-actions
git config user.email [email protected]
git add workflow-templates
git commit -m 'Update starter workflows'
for git_file in $(git ls-files); do
cat "$git_file"
done
# git push
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}