-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
74 lines (74 loc) · 2.44 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
name: 'Molnett - Ephemeral Environments'
description: 'Deploy or delete an ephemeral environment'
branding:
icon: 'download-cloud'
color: 'orange'
inputs:
action:
description: 'Either "deploy" or "delete"'
required: true
manifest-path:
description: 'Path to molnett manifest'
required: true
copy-from:
description: 'Which environment to copy resources (e.g. secrets) from'
outputs:
environment-name:
description: 'Name of the created environment'
value: ${{ steps.env-name.outputs.env }}
service-name:
description: 'Name of the deployed service'
value: ${{ steps.deploy.outputs.name }}
runs:
using: 'composite'
steps:
- name: Check Event
if: ${{ github.event_name != 'pull_request' }}
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
run: |
echo "::error title=⛔ error hint::action needs pull request event, was $EVENT_NAME"
exit 1
- name: Check Action
if: ${{ inputs.action != 'deploy' && inputs.action != 'delete' }}
shell: bash
run: |
echo "::error title=⛔ error hint::action needs to be deploy or delete"
exit 1
- name: Check Runner OS
if: ${{ runner.os != 'Linux' }}
shell: bash
run: |
echo "::error title=⛔ error hint::Support Linux Only"
exit 1
- name: Environment Name
id: env-name
shell: bash
env:
ENV_NAME: ${{ github.head_ref }}
run: |
# Replace special characters in branch name with dash
ENV_NAME=$(echo $ENV_NAME | tr $'!\'#$%&()+,-./;<=>@]_\`{|}' '-' | cut -c -30)
echo "env=$ENV_NAME" >> $GITHUB_OUTPUT
- name: Deploy Ephemeral Environment
id: deploy
if: ${{ inputs.action == 'deploy' }}
shell: bash
env:
ENV_NAME: ${{ steps.env-name.outputs.env }}
MANIFEST: ${{ inputs.manifest-path }}
COPY_FROM: ${{ inputs.copy-from }}
run: |
sed -i "s/environment:.*/environment: $ENV_NAME/" $MANIFEST
if [ $COPY_FROM ]; then molnctl environments create $ENV_NAME --copy-from=$COPY_FROM || true; else molnctl environments create $ENV_NAME || true; fi
molnctl services deploy --no-confirm $MANIFEST
FINAL_NAME=$(sed -n 's/name: //p' $MANIFEST | awk '{$1=$1};1')
echo "name=$FINAL_NAME" >> $GITHUB_OUTPUT
- name: Delete Ephemeral Environment
if: ${{ inputs.action == 'delete' }}
shell: bash
env:
ENV_NAME: ${{ steps.env-name.outputs.env }}
run: |
molnctl environments delete --no-confirm $ENV_NAME