-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
98 lines (87 loc) · 2.82 KB
/
action.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
name: "hcl-update"
description: "Update a HCL Variable in another repository "
inputs:
gh-token:
description: "An Access Token that has rights to read and write to the specificed repository."
required: true
variable:
description: "The variable that shall be overidden."
required: true
value:
description: "The new value that will be assigned to the variable"
required: true
repository:
description: "The repository that contains the HCL variable."
required: true
file-path:
description: "The path to the file where the variable is stored."
required: true
git-commit-message:
description: ""
required: true
git-branch-name:
description: ""
required: true
git-user-name:
description: ""
required: false
default: "machine-user"
git-email:
description: ""
required: false
runs:
using: "composite"
steps:
- name: Install hcledit
shell: bash
run: |
# Fetch hcledit binary
sudo wget https://github.com/minamijoyo/hcledit/releases/download/v0.2.6/hcledit_0.2.6_linux_amd64.tar.gz \
-O hcledit.tar.gz \
-q
# Validate checksum
SUM=c11b73643202936e835dfcb15b7d72211cbaed12b3740cab7a377156ebb36816
if [[ "$SUM" != "$(sha256sum hcledit.tar.gz | awk '{ print $1 }')" ]]
then
echo "hcledit checksum does not match"
exit 1;
fi
tar -xf hcledit.tar.gz
mv hcledit /usr/local/bin/hcledit
sudo chmod +x /usr/local/bin/hcledit
- name: Clone repository
shell: bash
run: |
git clone https://${{inputs.gh-token}}@${{inputs.repository}}.git repository
- name: Update variable
shell: bash
run: |
hcledit attribute set -f repository/${{inputs.file-path}} -u ${{inputs.variable}} '"${{inputs.value}}"'
- name: Set git user name
if: "${{ inputs.git-user-name != '' }}"
shell: bash
run: git config --global user.name ${{inputs.git-user-name}}
- name: Set git email
if: "${{ inputs.git-email != '' }}"
shell: bash
run: git config --global user.email ${{inputs.git-email}}
- name: Commit & create pull request
shell: bash
env:
GH_TOKEN: ${{ inputs.gh-token }}
run: |
# Checkout branch & commit
cd repository
git add -A
git checkout -b ${{inputs.git-branch-name}}
git commit -m "${{inputs.git-commit-message}}"
git push -u origin ${{inputs.git-branch-name}}
# Prepare
cat << EOF > body.md
This deployment is automatically generated from:
https://github.com/${GITHUB_REPOSITORY}/commit/${GITHUB_SHA}
Build URL:
https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}
EOF
# Create the pull request
gh pr create -f -F body.md