-
Notifications
You must be signed in to change notification settings - Fork 3
239 lines (214 loc) · 8.15 KB
/
release.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
name: release
run-name: Deploy by @${{ github.actor }} from ${{ github.ref_name }}
on:
workflow_dispatch:
inputs:
TARGET_ENVIRONMENT:
type: choice
description: "The environment to release to (dev, staging, prod)"
default: "dev"
required: true
options:
- dev
- staging
- prod
APPS:
type: string
description: "The apps to release, comma separated. E. g.: `go-highs-knapsack,java-ortools-knapsack`"
required: true
push:
branches:
- develop
permissions:
contents: read
packages: read
jobs:
determine_environments:
runs-on: ubuntu-latest
outputs:
environments: ${{ steps.set-environments.outputs.environments }}
steps:
- name: Set environments
id: set-environments
run: |
ENVIRONMENTS=""
if [ "${{ inputs.TARGET_ENVIRONMENT }}" != "" ]; then
echo "These are the environments to release => ${{ inputs.TARGET_ENVIRONMENT }}"
ENVIRONMENTS="['${{ inputs.TARGET_ENVIRONMENT }}']"
else
ENVIRONMENTS="['dev', 'staging', 'prod']"
fi
echo "These are the environments to release => ${ENVIRONMENTS}"
echo "environments=${ENVIRONMENTS}" >> $GITHUB_OUTPUT
update_apps:
runs-on: ubuntu-latest
needs: determine_environments
strategy:
fail-fast: false
matrix:
environment: ${{fromJson(needs.determine_environments.outputs.environments)}}
environment: ${{ matrix.environment }}
env:
BUCKET: ${{ secrets.S3_BUCKET }}
FOLDER: ${{ secrets.S3_FOLDER }}
MANIFEST: ${{ secrets.S3_MANIFEST }}
ROLE: ${{ secrets.AWS_DEVTOOLS_ROLE }}
REGION: ${{ secrets.AWS_REGION }}
GH_TOKEN: ${{ github.token }}
API_ENDPOINT: ${{ secrets.API_ENDPOINT }}
CONSOLE_URL: ${{ secrets.CONSOLE_URL }}
MARKETPLACE_API_KEY: ${{ secrets.MARKETPLACE_API_KEY }}
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
GO_VERSION: ""
PYTHON_VERSION: ""
APPS: ""
APP_NAMES: ""
FILTERS: ""
AUTOMATIC_APP_NAMES: false
permissions:
id-token: write
contents: write
steps:
- name: Configure git with the bot credentials
run: |
mkdir -p ~/.ssh
ssh-keyscan github.com >> ~/.ssh/known_hosts
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add - <<< "${{ secrets.NEXTMVBOT_SSH_KEY }}"
echo "${{ secrets.NEXTMVBOT_SIGNING_KEY }}" > ~/.ssh/signing.key
chmod 600 ~/.ssh/signing.key
git config --global user.name "nextmv-bot"
git config --global user.email "tech+gh-nextmv-bot@nextmv.io"
git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/signing.key
git clone git@github.com:nextmv-io/community-apps.git
cd community-apps
git fetch --all
git checkout ${{ github.ref_name }}
git pull
- name: determine if apps are provided through inputs or we need filters
run: |
export APPS="${{ inputs.APPS }}"
if [ $APPS != '' ]; then
echo "These are the apps to release => $APPS"
echo "APPS=${APPS}" >> $GITHUB_ENV
exit 0
fi
export AUTOMATIC_APP_NAMES=true
echo "AUTOMATIC_APP_NAMES=${AUTOMATIC_APP_NAMES}" >> $GITHUB_ENV
APP_NAMES_ARRAY=$(yq '.apps[].name' workflow-configuration.yml)
APP_NAMES=$(echo ${APP_NAMES_ARRAY[@]} | tr '\n' ' ')
echo "APP_NAMES=${APP_NAMES}" >> $GITHUB_ENV
FILTERS_FILE="../.github/filters.yml"
touch $FILTERS_FILE
for app in ${APP_NAMES[@]}; do
echo "${app}:" >> $FILTERS_FILE
echo " - '${app}/**'" >> $FILTERS_FILE
done
echo "Successfully created filters and wrote them to ${FILTERS_FILE}"
cat $FILTERS_FILE
working-directory: ./community-apps/.nextmv
- name: Filter changed directories
id: filter
if: ${{ env.AUTOMATIC_APP_NAMES == 'true' }}
uses: dorny/paths-filter@v3
with:
filters: .github/filters.yml
working-directory: ./community-apps
- name: Create comma-separated string of changed paths
if: ${{ env.AUTOMATIC_APP_NAMES == 'true' }}
run: |
export APPS=""
OUTPUTS=$(echo '${{ toJson(steps.filter.outputs) }}' | jq .)
for app in $(echo "${{ env.APP_NAMES }}"); do
if [ $(echo $OUTPUTS | jq -r --arg app "$app" '.[$app]') == "true" ]; then
APPS="${APPS}${app},"
fi
done
# Remove trailing comma
APPS="${APPS%,}"
echo "These are the apps to release => $APPS"
echo "APPS=${APPS}" >> $GITHUB_ENV
- name: set Python version
if: ${{ env.APPS != '' }}
run: |
export PYTHON_VERSION=$(yq '.language-support.python.version' workflow-configuration.yml)
echo "This is the Python version => $PYTHON_VERSION"
echo "PYTHON_VERSION=${PYTHON_VERSION}" >> $GITHUB_ENV
working-directory: ./community-apps/.nextmv
- name: set up Python
if: ${{ env.APPS != '' }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: set go version
if: ${{ env.APPS != '' }}
run: |
export GO_VERSION=$(yq '.language-support.go.version' workflow-configuration.yml)
echo "This is the Go version => $GO_VERSION"
echo "GO_VERSION=${GO_VERSION}" >> $GITHUB_ENV
working-directory: ./community-apps/.nextmv
- name: set up go
if: ${{ env.APPS != '' }}
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Install zig
if: ${{ env.APPS != '' }}
run: |
SIGNATURE="2d00e789fec4f71790a6e7bf83ff91d564943c5ee843c5fd966efc474b423047 zig-linux-x86_64-0.11.0.tar.xz"
curl -sSfL https://ziglang.org/download/0.11.0/zig-linux-x86_64-0.11.0.tar.xz -o zig-linux-x86_64-0.11.0.tar.xz
echo $SIGNATURE | sha256sum -c
tar -xf zig-linux-x86_64-0.11.0.tar.xz
sudo ln -s $PWD/zig-linux-x86_64-0.11.0/zig /usr/local/bin/zig
zig version
- name: Install Python dependencies
if: ${{ env.APPS != '' }}
run: |
pip install --upgrade pip
pip install -r requirements.txt
working-directory: ./community-apps/.nextmv/release
- name: Set up AWS CLI
if: ${{ env.APPS != '' }}
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ env.ROLE }}
aws-region: ${{ env.REGION }}
role-duration-seconds: 1200
- name: Set up JDK
if: ${{ env.APPS != '' }}
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
cache: "maven"
- name: Install Nextmv CLI
if: ${{ env.APPS != '' }}
run: |
export NEXTMV_API_KEY=$MARKETPLACE_API_KEY
export NEXTMV_BASE_URL=https://$API_ENDPOINT
curl -sS "https://$CONSOLE_URL/install-cli.txt" | bash -
- name: Set up Nextmv CLI
if: ${{ env.APPS != '' }}
run: |
export PATH=$PATH:~/.nextmv # Make CLI available in non-interactive shell
nextmv configure \
--api-key $MARKETPLACE_API_KEY \
-e $API_ENDPOINT
nextmv activate
nextmv sdk install
- name: Release the apps
if: ${{ env.APPS != '' }}
run: |
export PATH=$PATH:~/.nextmv # Make CLI available in non-interactive shell
export SLACK_NOTIFY_PARAM="" # Only notify slack for prod releases
if [ ${{ matrix.environment }} == "prod" ]; then
export SLACK_NOTIFY_PARAM="--slack-url ${{ secrets.SLACK_URL_MISSION_CONTROL }}"
fi
python main.py \
--apps "${{ env.APPS }}" \
--bucket "${{ env.BUCKET }}" \
--folder "${{ env.FOLDER }}" \
--manifest "${{ env.MANIFEST }}" \
$SLACK_NOTIFY_PARAM
working-directory: ./community-apps/.nextmv/release