-
Notifications
You must be signed in to change notification settings - Fork 4
151 lines (129 loc) · 4.35 KB
/
cloud_chatops.yaml
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
name: Cloud Chatops
on:
push:
branches:
- master
pull_request:
paths:
- ".github/workflows/cloud_chatops.yaml"
- "cloud-chatops/**"
jobs:
test_and_lint:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['ubuntu-20.04','ubuntu-22.04']
python-version: [ "3.12", "3.x" ]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install dependencies
run: |
cd cloud-chatops
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Analyse with pylint
run: |
cd cloud-chatops
pylint . --recursive=true --rcfile=.pylintrc
- name: Run tests
run: |
cd cloud-chatops
python3 -m pytest tests
- name: Run tests and collect coverage
run: |
cd cloud-chatops
python3 -m pytest tests --cov-report xml:coverage.xml --cov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{secrets.CODECOV_TOKEN}}
files: cloud-chatops/coverage.xml
push_dev_image_harbor:
runs-on: ubuntu-latest
needs: test_and_lint
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Harbor
uses: docker/login-action@v3
with:
registry: harbor.stfc.ac.uk
username: ${{ secrets.STAGING_HARBOR_USERNAME }}
password: ${{ secrets.STAGING_HARBOR_TOKEN }}
- name: Set commit SHA for later
id: commit_sha
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Build and push to staging project
uses: docker/build-push-action@v6
with:
cache-from: type=gha
cache-to: type=gha,mode=max
push: true
context: "{{defaultContext}}:cloud-chatops"
tags: "harbor.stfc.ac.uk/stfc-cloud-staging/cloud-chatops:${{ steps.commit_sha.outputs.sha_short }}"
check_version_update:
runs-on: ubuntu-latest
steps:
- name: Checkout master
uses: actions/checkout@v4
with:
ref: 'master'
path: 'main'
- name: Checkout current working branch
uses: actions/checkout@v4
with:
path: 'branch'
- name: Compare versions
if: ${{ github.ref != 'refs/heads/master' }}
uses: stfc/check-version-action@main
with:
app_version_path: "cloud-chatops/version.txt"
docker_compose_path: "cloud-chatops/docker-compose.yaml"
labels: ${{ toJSON(github.event.pull_request.labels.*.name) }}
- name: Log App Success
if: ${{ env.app_updated == 'true' }}
run: |
echo "App version has been updated correctly!"
- name: Log Compose Success
if: ${{ env.compose_updated == 'true' }}
run: |
echo "Compose version has been updated correctly!"
push_prod_image_harbor:
runs-on: ubuntu-latest
needs: [test_and_lint, check_version_update]
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Harbor
uses: docker/login-action@v3
with:
registry: harbor.stfc.ac.uk
username: ${{ secrets.HARBOR_USERNAME }}
password: ${{ secrets.HARBOR_TOKEN }}
- name: Get release tag for later
id: release_tag
run: echo "version=$(cat cloud-chatops/version.txt)" >> $GITHUB_OUTPUT
- name: Check if release file has updated
uses: dorny/paths-filter@v3
id: release_updated
with:
filters: |
version:
- 'cloud-chatops/version.txt'
- name: Build and push on version change
uses: docker/build-push-action@v6
if: steps.release_updated.outputs.version == 'true'
with:
cache-from: type=gha
cache-to: type=gha,mode=max
push: true
context: "{{defaultContext}}:cloud-chatops"
tags: "harbor.stfc.ac.uk/stfc-cloud/cloud-chatops:${{ steps.release_tag.outputs.version }}"