-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathaction.yml
191 lines (175 loc) · 6.19 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
name: 'Atlas CLI GitHub Action'
description: 'Use AtlasCLI in your GitHub workflow'
branding:
icon: 'terminal'
color: 'green'
inputs:
version:
description: Version of the Atlas CLI to install
required: false
create-project-name:
description: 'Name of the project that will be created.'
required: false
create-cluster-name:
description: 'Name of the cluster that will be created.'
required: false
delete-project-id:
description: 'Id of the project that will be deleted.'
required: false
delete-cluster-name:
description: 'Name of the cluster that will be deleted.'
required: false
project-id:
description: 'Id of the project.'
required: false
cluster-name:
description: 'Name of the cluster.'
required: false
run-setup:
description: 'This command takes you through registration, login, default profile creation and creating
your first free tier cluster'
required: false
default: 'false'
tier:
description: 'Tier of the created cluster.'
required: false
default: 'M0'
provider:
description: 'Provider of the created cluster.'
required: false
default: 'AWS'
region:
description: 'Region the cluster will be created in.'
required: false
default: US_EAST_1
username:
description: 'Username for the created cluster.'
required: false
password:
description: 'Password for the created cluster.'
required: false
outputs:
create-project-id:
description: 'ProjectId of the project that was created.'
value: ${{ steps.create-project.outputs.create-project-id }}
connection-string:
description: 'Connection String to use to connect to the created Cluster.'
value: ${{ steps.setup.outputs.connection-string }}
runs:
using: 'composite'
steps:
- name: Check Runner OS
if: ${{ runner.os != 'Linux' }}
shell: bash
run: |
echo "::error title=⛔ error hint::Support Linux Only"
exit 1
- name: Find latest tag
if: -z "${{ inputs.version }}"
uses: oprypin/find-latest-tag@v1
id: find-latest-tag
with:
repository: mongodb/mongodb-atlas-cli
releases-only: true
regex: 'atlascli*'
- name: Determine tag
id: determine-tag
shell: bash
run: |
if [ -z "${{ inputs.version }}" ]
then
echo "cli-tag=${{ steps.find-latest-tag.outputs.tag }}" >> $GITHUB_OUTPUT
else
echo "cli-tag=atlascli/${{ inputs.version }}" >> $GITHUB_OUTPUT
fi
- name: Download release
id: download-release
uses: robinraju/release-downloader@v1.11
with:
repository: mongodb/mongodb-atlas-cli
tag: ${{ steps.determine-tag.outputs.cli-tag }}
fileName: 'mongodb-atlas-cli*linux*.tar.gz'
out-file-path: /tmp
- name: Check Atlas CLI is installed
id: check-path
shell: bash
run: |
if ! which atlas >/dev/null 2>&1; then
# execute the following step only if the binary is not in PATH
echo "atlas-installed=0" >> $GITHUB_OUTPUT
exit 0
fi
echo "atlas-installed=1" >> $GITHUB_OUTPUT
- name: Install AtlasCLI
if: steps.check-path.outputs.atlas-installed == 0
shell: bash
run: |
if [ ${{ runner.arch }} = "ARM64" ]; then
ARCH="arm64"
elif [ ${{ runner.arch }} = "X64" ]; then
ARCH="x86_64"
else
echo "::error title=⛔ error hint::Support ARM64 and AMD64 Only"
exit 1
fi
tar -C /tmp -xzf /tmp/mongodb-atlas-cli_*_linux_${ARCH}.tar.gz
sudo mv /tmp/mongodb-atlas-cli_*_linux_${ARCH}/bin/atlas /usr/bin
- name: Create Project
if: ${{ inputs.create-project-name && inputs.run-setup == 'false' }}
shell: bash
id: create-project
env:
ATLAS_GITHUB_ACTION: "true"
run: |
projectId=$(atlas project create "${{ inputs.create-project-name }}" -o json-path="$.id")
echo "create-project-id=$(echo $projectId)" >> $GITHUB_OUTPUT
- name: Create Cluster
if: ${{ inputs.create-cluster-name && inputs.run-setup == 'false' }}
shell: bash
env:
ATLAS_GITHUB_ACTION: "true"
run: |
CLUSTER_CONFIG="--tier ${{ inputs.tier }} --provider ${{ inputs.provider }} --region ${{ inputs.region }}"
if [ -z "${{ inputs.project-id }}" ]
then
atlas cluster create ${{ inputs.create-cluster-name }} ${CLUSTER_CONFIG}
else
atlas cluster create ${{ inputs.create-cluster-name }} --projectId ${{ inputs.project-id }} ${CLUSTER_CONFIG}
fi
- name: Delete Cluster
if: ${{ inputs.delete-cluster-name && inputs.delete-project-id }}
shell: bash
env:
ATLAS_GITHUB_ACTION: "true"
run: |
atlas cluster delete ${{ inputs.delete-cluster-name }} --force --projectId ${{ inputs.delete-project-id }}
if ! atlas cluster watch ${{ inputs.delete-cluster-name }} --projectId ${{ inputs.delete-project-id }} >/dev/null 2>&1; then
echo "Atlas Cluster '${{ inputs.delete-cluster-name }}' is deleted"
exit 0
fi
- name: Delete Project
if: ${{ inputs.delete-project-id }}
shell: bash
env:
ATLAS_GITHUB_ACTION: "true"
run: |
atlas project delete ${{ inputs.delete-project-id }} --force
- name: Setup
if: ${{ inputs.run-setup == 'true' && inputs.username && inputs.password }}
shell: bash
id: setup
env:
ATLAS_GITHUB_ACTION: "true"
run: |
FLAGS="--force --currentIp --skipMongosh --skipSampleData --username ${{ inputs.username }} --password ${{ inputs.password }}"
CLUSTER_CONFIG="--tier ${{ inputs.tier }} --provider ${{ inputs.provider }} --region ${{ inputs.region }}"
if [ -n "${{ inputs.project-id }}" ]
then
FLAGS+=" --projectId ${{ inputs.project-id }}"
fi
if [ -n "${{ inputs.cluster-name }}" ]
then
FLAGS+=" --clusterName ${{ inputs.cluster-name }}"
fi
connectionString=$(atlas setup ${FLAGS} ${CLUSTER_CONFIG} | sed -n 's/Your connection string: //p')
echo "connection-string=$(echo $connectionString)" >> $GITHUB_OUTPUT