-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (76 loc) · 3.12 KB
/
create-environment.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
name: Create folders and projects
on:
workflow_dispatch:
inputs:
department:
type: string
required: true
service:
type: string
required: true
hierarchy_setters:
type: string
required: true
project_setters:
type: string
required: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Create directory if not exists
run: |
mkdir -p manifests/landing-zone/hierarchy
mkdir -p manifests/landing-zone/projects/${{ inputs.department }}
- name: Get hierarchy kpt package
uses: docker://gcr.io/kpt-dev/kpt:v1.0.0-beta.9
with:
args: pkg get https://github.com/yoshimasak/configcontroller-selfservice-sample.git/manifests/hierarchy@main manifests/landing-zone/hierarchy/${{ inputs.department }}
- name: Get project kpt package
uses: docker://gcr.io/kpt-dev/kpt:v1.0.0-beta.9
with:
args: pkg get https://github.com/yoshimasak/configcontroller-selfservice-sample.git/manifests/projects@main manifests/landing-zone/projects/${{ inputs.department }}/${{ inputs.service }}
- name: Change permission
run: |
sudo chown -R runner:docker manifests/landing-zone/hierarchy/${{ inputs.department }}
sudo chown -R runner:docker manifests/landing-zone/projects/${{ inputs.department }}
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '16.x'
- run: npm install js-yaml
- uses: actions/github-script@v6
with:
script: |
const fs = require('fs')
const jsyaml = require('js-yaml')
var payload = ${{ inputs.hierarchy_setters }}
var json = JSON.parse(JSON.stringify(payload))
var yaml = jsyaml.dump(json)
console.log(yaml)
fs.writeFile('manifests/landing-zone/hierarchy/${{ inputs.department }}/setters.yaml', yaml, 'utf8', (err) => {
if (err) {
console.error(err.message)
}
})
payload = ${{ inputs.project_setters }}
json = JSON.parse(JSON.stringify(payload))
yaml = jsyaml.dump(json)
console.log(yaml)
fs.writeFile('manifests/landing-zone/projects/${{ inputs.department }}/${{ inputs.service }}/setters.yaml', yaml, 'utf8', (err) => {
if (err) {
console.error(err.message)
}
})
- name: Git push
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git add manifests/
git commit -m ":robot: Create folder at `date --iso-8601=seconds`"
git push origin main:dev
- name: Create pull request
run: gh pr create -B "main" -t "Create ${{ inputs.department }} folder and ${{ inputs.department }}-${{ inputs.service }} projects" -H dev -b "Review request for creating a new folder and project."
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}