-
Notifications
You must be signed in to change notification settings - Fork 0
148 lines (130 loc) · 5.74 KB
/
main.yaml
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: Update Values File
on:
push:
branches:
- main
- dev
tags:
- "v*" # Triggered by tags starting with 'v'
jobs:
update-values:
runs-on: ubuntu-latest
steps:
- name: echo Hello
run: echo "Hello"
# - name: Generate a token
# id: generate-token
# uses: actions/create-github-app-token@v1
# with:
# app-id: ${{ secrets.GITOPS_RUNNER_APP_ID }}
# private-key: ${{ secrets.GITOPS_RUNNER_PRIVATE_KEY }}
# owner: ditkrg
# repositories: "pilgrimage-gitops-duplicate"
# - uses: actions/checkout@v4
# with:
# repository: ditkrg/pilgrimage-gitops-duplicate
# token: ${{ steps.generate-token.outputs.token }}
# - name: Determine Environment
# id: env
# run: |
# if [[ $GITHUB_REF == refs/tags/* ]]; then
# environment=production
# elif [[ $GITHUB_REF == refs/heads/main ]]; then
# environment=staging
# else
# environment=dev
# fi
# echo "::set-output name=environment::${environment}"
# - name: Determine Component Name
# id: component
# run: |
# component=oauth2-proxy
# echo "::set-output name=component::${component}"
# - id: get-environment
# run: |
# if [[ $GITHUB_REF == refs/tags/* ]]; then
# environment=production
# elif [[ $GITHUB_REF == refs/heads/main ]]; then
# environment=staging
# else
# environment=dev
# fi
# echo "::set-output name=environment::${environment}"
# - id: find-target-file
# run: |
# environment=${{ steps.env.outputs.environment }}
# component=${{ steps.component.outputs.component }}
# if [ $environment == "production" ]; then
# target_file="overlays/production/image.yaml"
# elif [ $environment == "staging" ]; then
# target_file="overlays/staging/image.yaml"
# else
# target_file="overlays/development/image.yaml"
# fi
# echo "::set-output name=target_file::${target_file}"
# - id: create-label
# run: |
# # Define your GitHub repository and access token
# REPO="ditkrg/pilgrimage-gitops-duplicate"
# # Define the label you want to check and create if it doesn't exist
# LABEL_NAME="autodeploy"
# LABEL_COLOR="00FF00" # You can specify a color in hexadecimal format
# # Make a request to fetch the list of labels
# response=$(curl -s -H "Authorization: token ${{ steps.generate-token.outputs.token }}" "https://api.github.com/repos/$REPO/labels")
# # Check if the label exists in the response
# if [[ "$response" == *"$LABEL_NAME"* ]]; then
# echo "Label '$LABEL_NAME' exists in the repository."
# else
# echo "Label '$LABEL_NAME' does not exist in the repository. Creating it..."
# # Create the label using the GitHub API
# curl -X POST "https://api.github.com/repos/$REPO/labels" \
# -H "Authorization: token ${{ steps.generate-token.outputs.token }}" \
# -d "{\"name\":\"$LABEL_NAME\",\"color\":\"$LABEL_COLOR\"}"
# echo "Label '$LABEL_NAME' has been created."
# fi
# - run: |
# environment=${{ steps.env.outputs.environment }}
# component=${{ steps.component.outputs.component }}
# branch_name="update-$component-$environment"
# # Do not create a new branch if the branch already exists
# if [[ $(git ls-remote origin $branch_name) ]]; then
# git fetch origin
# git checkout $branch_name
# else
# git checkout -b $branch_name
# git push --set-upstream origin $branch_name
# fi
# # Use the REST API to commit changes, so we get automatic commit signing
# - run: |
# # Update the image.yaml file with the new image tag
# echo "image:" > $TARGET_FILE
# echo " tag: V1.2.6" >> $TARGET_FILE
# export MESSAGE="chore: Update $TARGET_FILE for to V1.2.6"
# export SHA=$( git rev-parse $DESTINATION_BRANCH:$TARGET_FILE )
# export CONTENT=$( base64 -i $TARGET_FILE )
# gh api --method PUT /repos/ditkrg/pilgrimage-gitops-duplicate/contents/$TARGET_FILE \
# --field message="$MESSAGE" \
# --field content="$CONTENT" \
# --field encoding="base64" \
# --field branch="$DESTINATION_BRANCH" \
# --field sha="$SHA"
# env:
# GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
# DESTINATION_BRANCH: update-${{ steps.component.outputs.component }}-${{ steps.env.outputs.environment }}
# TARGET_FILE: ${{ steps.component.outputs.component }}/${{ steps.find-target-file.outputs.target_file }}
# - name: Create Pull Request
# run: |
# # do not create the PR if it already exists from the same branch
# if [[ $(gh pr list --state open --head $HEAD_BRANCH) ]]; then
# echo "PR already exists"
# else gh pr create \
# --body "" \
# --title "Update $component/$target_file for $environment" \
# --label autodeploy
# fi
# env:
# GH_TOKEN: ${{ steps.generate-token.outputs.token }}
# environment: ${{ steps.env.outputs.environment }}
# component: ${{ steps.component.outputs.component }}
# target_file: ${{ steps.find-target-file.outputs.target_file }}
# HEAD_BRANCH: update-${{ steps.component.outputs.component }}-${{ steps.env.outputs.environment }}