-
Notifications
You must be signed in to change notification settings - Fork 0
91 lines (77 loc) · 3.39 KB
/
update-starter-workflows.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
name: Update starter workflows
on:
push:
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: 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: Checkout .github repository
uses: actions/checkout@v4
with:
path: 'dotgithub'
repository: '3lvia/.github'
token: ${{ steps.app-token.outputs.token }}
- name: Update workflows-templates
shell: bash
run: |
mkdir -p dotgithub/workflow-templates
for workflow_path in ${{ env.REPOSITORY }}/.github/workflows/example-*.yml; do
file_name=$(basename "$workflow_path")
file_name_no_prefix="${file_name#example-}"
new_workflow_path="dotgithub/workflow-templates/$file_name_no_prefix"
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.yml'/ 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 (or leave empty if Dockerfile in root dir)>'/g" "$new_workflow_path"
sed -i 's/branches: \[trunk\]/branches: \[$default-branch\]/g' "$new_workflow_path"
new_workflow_properties_file="dotgithub/workflow-templates/${file_name_no_prefix%.yml}.properties.json"
if [ ! -f "$new_workflow_properties_file" ]; then
echo "Creating properties.json file for $new_workflow_path."
new_workflow_name=$(yq -r '.name' "$new_workflow_path")
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: |
if [[ -z "$(git status --porcelain)" ]]; then
echo 'No changes to commit.'
# exit 0
fi
gh_app_user_id="$(curl -gs https://api.github.com/users/$GH_APP_USERNAME | jq -r '.id')"
gh_app_user_email="[email protected]"
git config user.email "$gh_app_user_email"
git config user.name "$GH_APP_USERNAME"
git add workflow-templates
git commit -m 'Update starter workflows'
for git_file in $(git ls-files); do
cat "$git_file"
done
git push
working-directory: 'dotgithub'
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
GH_APP_USERNAME: '3lvia-core-admin[bot]'