-
Notifications
You must be signed in to change notification settings - Fork 0
149 lines (124 loc) · 4.65 KB
/
Copy pathpython-script.yaml
File metadata and controls
149 lines (124 loc) · 4.65 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
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
name: Python script testing
on:
push:
branches:
- feature/python-script
workflow_dispatch:
env:
WERF_CHANNEL: "ea"
jobs:
job1:
name: Generate channel releases
runs-on: ubuntu-latest
outputs:
STABLE_VERSION: ${{ steps.channel-collector.outputs.stable_version }}
DEPLOY_KUBECONFIG_BASE64_DEV: ${{ steps.channel-collector.outputs.DEPLOY_KUBECONFIG_BASE64_DEV }}
LATEST_RELEASE_ID: ${{ steps.channel-collector.outputs.latest_release_id }}
TARGET_RELEASE_ID: ${{ steps.channel-collector.outputs.target_release_id }}
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check runner fs structure
run: |
echo "Current dir" && pwd
echo "Check files" && ls -lah
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12.3'
- name: Install dependencies
run: pip install ghapi fastcore kubernetes
- name: Prepare files for collecting and deployment
run: |
mkdir -p ci/.helm/templates
echo -e "project: deckhouse-channels\nconfigVersion: 1" | tee werf.yaml ci/werf.yaml
echo "Print content of ci/werf.yaml" && cat ci/werf.yaml
tee ci/.helm/templates/configmap.yaml << EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: release-channels-data
data:
channels.yaml: |
{{ $.Files.Get "channels.yaml" | indent 4 }}
EOF
echo "Print file structure of ci directory:"
ls -1RA ci
echo "Print content of ci/.helm/templates/configmap.yaml"
cat ci/.helm/templates/configmap.yaml
- name: Collect release versions
id: channel-collector
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
KUBECONFIG_BASE64_DEV: "${{ secrets.WERF_KUBECONFIG_BASE64 }}"
NAMESPACE_KUBECONFIG_BASE64_DEV: "deckhouse-web-dev"
run: python scripts/collect-released-versions.py
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: channels-artifact
path: ci
include-hidden-files: true
- name: Check outputs
run: |
echo "${{ steps.channel-collector.outputs.stable_version }}"
echo "${{ steps.channel-collector.outputs.dev_deploy }}"
job2:
if: ${{ needs.job1.outputs.DEPLOY_KUBECONFIG_BASE64_DEV == 'true' }}
name: Deploy channel releases
runs-on: ubuntu-latest
needs: job1
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Download channels artifact
uses: actions/download-artifact@v4
with:
name: channels-artifact
path: channel-releases
- name: Check runner's file structure
run: ls -1RA
- name: Install werf CLI
uses: werf/actions/install@v2
- name: Converge
uses: werf/actions/converge@v2
with:
channel: ${{env.WERF_CHANNEL}}
kube-config-base64-data: "${{ secrets.WERF_KUBECONFIG_BASE64 }}"
env: dev
env:
WERF_NAMESPACE: "deckhouse-web-dev"
WERF_DIR: "channel-releases"
WERF_DEV: "true"
job3:
if: ${{ (github.ref_name == needs.job1.outputs.STABLE_VERSION) && (needs.job1.outputs.TARGET_RELEASE_ID != needs.job1.outputs.LATEST_RELEASE_ID) }}
name: Update
runs-on: ubuntu-latest
needs: job1
permissions:
contents: write
steps:
- name: Make latest stable release
env:
STABLE_VERSION: ${{ needs.job1.outputs.STABLE_VERSION }}
TARGET_RELEASE_ID: ${{ needs.job1.outputs.TARGET_RELEASE_ID }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
url="${GITHUB_API_URL}"
owner="${GITHUB_REPOSITORY%/*}"
repo="${GITHUB_REPOSITORY#*/}"
update_release="${url}/repos/${GITHUB_REPOSITORY}/releases/${TARGET_RELEASE_ID}"
response=$(curl -s -w "\n%{http_code}" -X PATCH ${update_release} \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-d '{"prerelease":false,"make_latest":true}') || exit $?
response_code=$(echo "$response" | tail -n1)
if [[ $response_code != '200' ]]; then
echo -e "\e[31mERROR: Unable to update release ${TARGET_RELEASE_ID}!\e[0m"
echo -e "\e[31mURL: ${update_release}!\e[0m"
echo -e "\e[31mResponse code: ${response_code}!\e[0m"
exit 1
fi
echo -e "\e[32mRelease ${TARGET_RELEASE_ID} has been successfully marked as latest."