Add examples & publish starter workflows on push #9
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: Update starter workflows | |
on: | |
push: | |
branches: [trunk] | |
pull_request: | |
branches: [trunk] | |
env: | |
REPOSITORY: 'core-github-actions-templates' | |
jobs: | |
update-starter-workflows: | |
name: Update starter workflows | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
path: ${{ env.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 ${{ env.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>'/g" "$new_workflow_path" | |
sed -i "s/ HELM_VALUES_PATH: '.github\/test\/deploy\/values.yaml'/ HELM_VALUES_PATH: '<your Helm values path here>'/g" "$new_workflow_path" | |
sed -i "s/ DOCKERFILE: '.github\/test\/src\/Dockerfile'/ DOCKERFILE: '<your Dockerfile path here>'/g" "$new_workflow_path" | |
new_workflow_properties_file="$new_workflow_path.properties.json" | |
if [ ! -f "$new_workflow_properties_file" ]; then | |
echo "Creating properties.json file for $new_workflow_path." | |
new_workflow_name=$(cat "$new_workflow_path" | yq '.name') | |
cat << EOF > "$new_workflow_properties_file" | |
{ | |
"name": $new_workflow_name, | |
"description": $new_workflow_name | |
} | |
EOF | |
else | |
echo "Properties file already exists for $new_workflow_path, will not overwrite." | |
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 }} |