forked from alchemy-run/alchemy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
83 lines (78 loc) · 2.72 KB
/
Copy pathaction.yml
File metadata and controls
83 lines (78 loc) · 2.72 KB
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
name: Alchemy
description: Deploy Alchemy stages for pull requests and the main branch, and destroy pull request stages when closed.
author: alchemy-run
branding:
icon: upload-cloud
color: green
inputs:
working-directory:
description: Directory where the Alchemy project should be run.
required: false
default: .
main-branch:
description: Branch that deploys as the persistent prod stage and is never destroyed.
required: false
default: main
outputs:
action:
description: "The lifecycle action that ran: deploy, destroy, or skip."
value: ${{ steps.resolve.outputs.action }}
stage:
description: The Alchemy stage name.
value: ${{ steps.resolve.outputs.stage }}
pull-request:
description: The pull request number for PR stages.
value: ${{ steps.resolve.outputs.pull-request }}
runs:
using: composite
steps:
- id: resolve
shell: bash
env:
MAIN_BRANCH: ${{ inputs.main-branch }}
EVENT_NAME: ${{ github.event_name }}
EVENT_ACTION: ${{ github.event.action }}
REF_NAME: ${{ github.ref_name }}
PR_NUMBER: ${{ github.event.number }}
run: |
if [ "$EVENT_NAME" = "pull_request" ]; then
echo "stage=staging-$PR_NUMBER" >> "$GITHUB_OUTPUT"
echo "pull-request=$PR_NUMBER" >> "$GITHUB_OUTPUT"
if [ "$EVENT_ACTION" = "closed" ]; then
echo "action=destroy" >> "$GITHUB_OUTPUT"
else
echo "action=deploy" >> "$GITHUB_OUTPUT"
fi
exit 0
fi
if [ "$REF_NAME" = "$MAIN_BRANCH" ]; then
echo "stage=prod" >> "$GITHUB_OUTPUT"
echo "pull-request=" >> "$GITHUB_OUTPUT"
echo "action=deploy" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "stage=" >> "$GITHUB_OUTPUT"
echo "pull-request=" >> "$GITHUB_OUTPUT"
echo "action=skip" >> "$GITHUB_OUTPUT"
- if: ${{ steps.resolve.outputs.action == 'deploy' }}
shell: bash
working-directory: ${{ inputs.working-directory }}
env:
STAGE: ${{ steps.resolve.outputs.stage }}
PULL_REQUEST_VALUE: ${{ steps.resolve.outputs.pull-request }}
run: |
if [ -n "$PULL_REQUEST_VALUE" ]; then
export PULL_REQUEST="$PULL_REQUEST_VALUE"
fi
alchemy deploy --stage "$STAGE" --yes
- if: ${{ steps.resolve.outputs.action == 'destroy' }}
shell: bash
working-directory: ${{ inputs.working-directory }}
env:
STAGE: ${{ steps.resolve.outputs.stage }}
PULL_REQUEST_VALUE: ${{ steps.resolve.outputs.pull-request }}
run: |
if [ -n "$PULL_REQUEST_VALUE" ]; then
export PULL_REQUEST="$PULL_REQUEST_VALUE"
fi
alchemy destroy --stage "$STAGE" --yes