-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
action.yml
80 lines (72 loc) · 2.28 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
name: 'Preview environment controller'
description: 'Action to manage to deploy and purge preview environments depends on PR labels'
author: hello@cloudposse.com
branding:
icon: 'layers'
color: 'white'
inputs:
env-label:
description: "YAML formatted {environment}: {label} map "
required: true
default: |
preview: deploy
labels:
description: Existing PR labels
required: true
default: "[]"
open:
required: true
description: "Is PR open?"
default: "true"
outputs:
labels_env:
description: "JSON formatted {label}: {environment} map"
value: ${{ steps.yaml2json.outputs.output }}
deploy_envs:
description: "Environments that need to be deployed"
value: ${{ steps.deploy_envs.outputs.output }}
destroy_envs:
description: "Environments that need to be destroyed"
value: ${{ steps.destroy_envs.outputs.output }}
runs:
using: "composite"
steps:
- uses: 1arp/create-a-file-action@0.3
with:
path: './'
file: 'labels_env.yaml'
content: ${{ inputs.env-label }}
- uses: fabasoad/data-format-converter-action@64006df7988ff8c87b38e53fcaf5843d4fe340cc # > v0.2.1
id: yaml2json
with:
input: 'labels_env.yaml'
from: 'yaml'
to: 'json'
- id: pattern
shell: bash
run: |
if [ "${{ inputs.open }}" == "true" ]
then
echo "deploy=with_entries(select(.value | IN({0}[]))) | keys" >> $GITHUB_OUTPUT
echo "destroy=with_entries(select(.value | IN({0}[]) | not )) | keys" >> $GITHUB_OUTPUT
else
echo "deploy=[]" >> $GITHUB_OUTPUT
echo "destroy=with_entries(select(.value | IN({0}[]))) | keys" >> $GITHUB_OUTPUT
fi
- name: 'Install jq 1.6'
uses: dcarbone/install-jq-action@v2.1.0
with:
version: 1.6
force: 'true'
- uses: cloudposse/github-action-jq@0.4.0
id: deploy_envs
with:
compact: true
input: ${{ steps.yaml2json.outputs.output }}
script: ${{ format(steps.pattern.outputs.deploy, inputs.labels) }}
- uses: cloudposse/github-action-jq@0.4.0
id: destroy_envs
with:
compact: true
input: ${{ steps.yaml2json.outputs.output }}
script: ${{ format(steps.pattern.outputs.destroy, inputs.labels) }}