generated from keptn-sandbox/keptn-service-template-go
-
Notifications
You must be signed in to change notification settings - Fork 0
114 lines (112 loc) · 6.85 KB
/
initrepo.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
name: One-time repository initialization
on:
workflow_dispatch:
env:
ORIGINAL_IMAGE_NAME: ghcr.io/keptn-sandbox/keptn-service-template-go
NEW_IMAGE_NAME: ghcr.io/${{ github.repository }}
ORIGINAL_SERVICE_NAME: keptn-service-template-go
TARGET_BRANCH: patch/initialize-repo
ORIGINAL_REPO_NAME: keptn-sandbox/keptn-service-template-go
NEW_REPO_NAME: ${{ github.repository }}
jobs:
init_repo_job:
runs-on: ubuntu-latest
name: A job to initialize a repository freshly cloned from the template
steps:
- name: Checkout
uses: actions/[email protected]
- name: Setup Go
uses: actions/[email protected]
with:
go-version-file: "go.mod"
- run: go version
- name: Update the image name in .ci_env, helm chart and skaffold
run: |
ESCAPED_ORIGINAL=$(printf '%s\n' "$ORIGINAL_IMAGE_NAME" | tr '[:upper:]' '[:lower:]' | sed -e 's/[\/&]/\\&/g')
ESCAPED_REPLACE=$(printf '%s\n' "$NEW_IMAGE_NAME" | tr '[:upper:]' '[:lower:]' | sed -e 's/[\/&]/\\&/g')
sed -i "s/${ESCAPED_ORIGINAL}/${ESCAPED_REPLACE}/g" chart/values.yaml skaffold.yaml chart/README.md
NEW_SERVICE_NAME=$(echo ${{ github.repository }} | sed -e 's/${{ github.repository_owner }}\///')
ESCAPED_ORIGINAL=$(printf '%s\n' "$ORIGINAL_SERVICE_NAME" | tr '[:upper:]' '[:lower:]' | sed -e 's/[\/&]/\\&/g')
ESCAPED_REPLACE=$(printf '%s\n' "$NEW_SERVICE_NAME" | tr '[:upper:]' '[:lower:]' | sed -e 's/[\/&]/\\&/g')
sed -i "s/${ESCAPED_ORIGINAL}/${ESCAPED_REPLACE}/g" skaffold.yaml chart/README.md .ci_env
- name: Update chart name, version and service name
run: |
NEW_SERVICE_NAME=$(echo ${{ github.repository }} | sed -e 's/${{ github.repository_owner }}\///')
ESCAPED_ORIGINAL=$(printf '%s\n' "$ORIGINAL_SERVICE_NAME" | tr '[:upper:]' '[:lower:]' | sed -e 's/[\/&]/\\&/g')
ESCAPED_REPLACE=$(printf '%s\n' "$NEW_SERVICE_NAME" | tr '[:upper:]' '[:lower:]' | sed -e 's/[\/&]/\\&/g')
sed -i "s/${ESCAPED_ORIGINAL}/${ESCAPED_REPLACE}/g" ./**/*.yaml
sed -irn 's/version:.*$/version: "0.1.0"/g' chart/Chart.yaml
sed -irn 's/appVersion:.*$/appVersion: "0.1.0"/g' chart/Chart.yaml
- name: Update .gitignore, Dockerfile and GetSLI eventhandler
run: |
NEW_SERVICE_NAME=$(echo ${{ github.repository }} | sed -e 's/${{ github.repository_owner }}\///')
ESCAPED_ORIGINAL=$(printf '%s\n' "$ORIGINAL_SERVICE_NAME" | sed -e 's/[\/&]/\\&/g')
ESCAPED_REPLACE=$(printf '%s\n' "$NEW_SERVICE_NAME" | sed -e 's/[\/&]/\\&/g')
sed -i "s/${ESCAPED_ORIGINAL}/${ESCAPED_REPLACE}/g" .ci_env .gitignore Dockerfile main.go eventhandlers.go eventhandler_test.go test-events/*.json
- name: Update README.md
run: |
ESCAPED_ORIGINAL=$(printf '%s\n' "$ORIGINAL_IMAGE_NAME" | tr '[:upper:]' '[:lower:]' | sed -e 's/[\/&]/\\&/g')
ESCAPED_REPLACE=$(printf '%s\n' "$NEW_IMAGE_NAME" | tr '[:upper:]' '[:lower:]' | sed -e 's/[\/&]/\\&/g')
sed -i "s/${ESCAPED_ORIGINAL}/${ESCAPED_REPLACE}/g" README.md
ESCAPED_ORIGINAL=$(printf '%s\n' "$ORIGINAL_REPO_NAME" | tr '[:upper:]' '[:lower:]' | sed -e 's/[\/&]/\\&/g')
ESCAPED_REPLACE=$(printf '%s\n' "$NEW_REPO_NAME" | tr '[:upper:]' '[:lower:]' | sed -e 's/[\/&]/\\&/g')
sed -i "s/${ESCAPED_ORIGINAL}/${ESCAPED_REPLACE}/g" README.md
NEW_SERVICE_NAME=$(echo ${{ github.repository }} | sed -e 's/${{ github.repository_owner }}\///')
ESCAPED_ORIGINAL=$(printf '%s\n' "$ORIGINAL_SERVICE_NAME" | tr '[:upper:]' '[:lower:]' | sed -e 's/[\/&]/\\&/g')
ESCAPED_REPLACE=$(printf '%s\n' "$NEW_SERVICE_NAME" | tr '[:upper:]' '[:lower:]' | sed -e 's/[\/&]/\\&/g')
sed -i "s/${ESCAPED_ORIGINAL}/${ESCAPED_REPLACE}/g" README.md
- name: Update go module name
run: |
NEW_GO_MODULE=$(echo ${{ github.repositoryUrl }} | sed -rn 's/.*:(\/\/)?(github\.com\/.+)\.git/\2/p')
go mod edit -module ${NEW_GO_MODULE}
- name: Install Helm
uses: azure/setup-helm@v1
with:
version: v3.7.1
- name: Update CODEOWNERS file
run: echo '* @${{ github.actor }}' >> CODEOWNERS
- name: Dump rendered helm chart
run: helm template chart
- name: Show git diff
run: git diff
- name: Configure Git
run: |
git config user.name "GitHub Actions" # "${{ github.actor }}"
git config user.email "[email protected]" # "${{ github.actor }}@users.noreply.github.com"
- name: "Commit changes to a branch and open Pull Request"
run: |
echo "Fetching origin including tags..."
git fetch origin --tags -f
# delete existing branch just in case
git branch -D ${TARGET_BRANCH} &>/dev/null || true
# create new branch
git checkout -b ${TARGET_BRANCH}
# add changes
echo "Add changes and commit"
git commit -as -m "chore: initialize template after cloning"
# push changes
echo "⚡️ Pushing changes to remote repository..."
git push -f --follow-tags --set-upstream origin ${TARGET_BRANCH}
- name: "Find other substitutions and commit again"
run: |
ESCAPED_ORIGINAL=$(printf '%s\n' "$ORIGINAL_IMAGE_NAME" | tr '[:upper:]' '[:lower:]' | sed -e 's/[\/&]/\\&/g')
ESCAPED_REPLACE=$(printf '%s\n' "$NEW_IMAGE_NAME" | tr '[:upper:]' '[:lower:]' | sed -e 's/[\/&]/\\&/g')
find . -type f -not -path '*/.git/*' -not -path '*/.github/*' -print0 | xargs -0 sed -i "s/${ESCAPED_ORIGINAL}/${ESCAPED_REPLACE}/g"
ESCAPED_ORIGINAL=$(printf '%s\n' "$ORIGINAL_REPO_NAME" | sed -e 's/[\/&]/\\&/g')
ESCAPED_REPLACE=$(printf '%s\n' "$NEW_REPO_NAME" | sed -e 's/[\/&]/\\&/g')
find . -type f -not -path '*/.git/*' -not -path '*/.github/*' -print0 | xargs -0 sed -i "s/${ESCAPED_ORIGINAL}/${ESCAPED_REPLACE}/g"
NEW_SERVICE_NAME=$(echo ${{ github.repository }} | sed -e 's/${{ github.repository_owner }}\///')
ESCAPED_ORIGINAL=$(printf '%s\n' "$ORIGINAL_SERVICE_NAME" | sed -e 's/[\/&]/\\&/g')
ESCAPED_REPLACE=$(printf '%s\n' "$NEW_SERVICE_NAME" | sed -e 's/[\/&]/\\&/g')
find . -type f -not -path '*/.git/*' -not -path '*/.github/*' -print0 | xargs -0 sed -i "s/${ESCAPED_ORIGINAL}/${ESCAPED_REPLACE}/g"
# add changes
echo "Add changes and commit"
git commit -as -m "chore: further substitutions" || true
# push changes
echo "⚡️ Pushing changes to remote repository..."
git push
- name: Create Pull Request"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr create --title "chore: Initialize template repository after cloning" --body "**This is an automated PR for one-time init of keptn service template**" --base "${GITHUB_REF##refs/heads/}"