Skip to content

Commit d565591

Browse files
SonnyBASonny Bakker
and
Sonny Bakker
committed
[#13] reuse open-api-workflows workflows (#447)
* [#13] reuse open-api-workflows workflows --------- Co-authored-by: Sonny Bakker <sonny@maykinmedia.nl>
1 parent 7060252 commit d565591

23 files changed

+316
-487
lines changed

.github/workflows/ci.yml

+36-102
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,12 @@ jobs:
2929

3030
steps:
3131
- uses: actions/checkout@v4
32-
- uses: actions/setup-python@v5
32+
- name: Set up backend environment
33+
uses: maykinmedia/setup-django-backend@v1.3
3334
with:
35+
apt-packages: 'libgdal-dev gdal-bin'
3436
python-version: '3.11'
35-
- uses: actions/setup-node@v4
36-
with:
37-
node-version: '18'
38-
39-
- name: Install system packages
40-
run: |
41-
sudo apt-get update \
42-
&& sudo apt-get install -y --no-install-recommends \
43-
libgdal-dev \
44-
gdal-bin
45-
46-
- name: Install dependencies
47-
run: pip install -r requirements/ci.txt codecov
48-
- name: Build frontend
49-
run: |
50-
npm ci
51-
npm run build
37+
setup-node: true
5238

5339
- name: Run tests
5440
run: |
@@ -61,27 +47,21 @@ jobs:
6147
DB_PASSWORD: ''
6248

6349
- name: Publish coverage report
64-
uses: codecov/codecov-action@v3
50+
uses: codecov/codecov-action@v4
6551

6652
docs:
6753
runs-on: ubuntu-latest
6854
name: Documentation build
6955

7056
steps:
7157
- uses: actions/checkout@v4
72-
- uses: actions/setup-python@v5
58+
- name: Set up backend environment
59+
uses: maykinmedia/setup-django-backend@v1.3
7360
with:
61+
apt-packages: 'libgdal-dev gdal-bin'
7462
python-version: '3.11'
75-
cache: 'pip'
76-
cache-dependency-path: 'requirements/*.txt'
77-
- name: Install system packages
78-
run: |
79-
sudo apt-get update \
80-
&& sudo apt-get install -y --no-install-recommends \
81-
libgdal-dev \
82-
gdal-bin
83-
- name: Install dependencies
84-
run: pip install -r requirements/ci.txt pytest
63+
setup-node: false
64+
8565
- name: Generate environment variable documentation using OAf and check if it was updated
8666
run: |
8767
bin/generate_envvar_docs.sh
@@ -94,81 +74,35 @@ jobs:
9474
env:
9575
DJANGO_SETTINGS_MODULE: objects.conf.ci
9676

97-
docker:
98-
needs: tests
99-
100-
name: Build (and push) Docker image
77+
store-reusable-workflow-vars:
78+
name: create values which can be passed through a reusable workflow
10179
runs-on: ubuntu-latest
80+
outputs:
81+
image-name: ${{ steps.image-name.outputs.image-name }}
10282

10383
steps:
104-
- uses: actions/checkout@v4
105-
106-
- name: Set tag
107-
id: vars
108-
run: |
109-
# Strip git ref prefix from version
110-
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
111-
112-
# Strip "v" prefix from tag name (if present at all)
113-
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
114-
115-
# Use Docker `latest` tag convention
116-
[ "$VERSION" == "master" ] && VERSION=latest
117-
118-
echo ::set-output name=tag::${VERSION}
119-
120-
- name: Build the Docker image
121-
env:
122-
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
123-
run: docker build . --tag $IMAGE_NAME:$RELEASE_VERSION
124-
125-
- run: docker image save -o image.tar $IMAGE_NAME:${{ steps.vars.outputs.tag }}
126-
127-
- name: Store image artifact
128-
uses: actions/upload-artifact@v3
129-
with:
130-
name: docker-image
131-
path: image.tar
132-
retention-days: 1
84+
- run: echo "image-name=$IMAGE_NAME" >> $GITHUB_OUTPUT
85+
name: 'Store the docker image name'
86+
id: image-name
13387

134-
publish:
88+
open-api-ci:
89+
uses: maykinmedia/open-api-workflows/.github/workflows/ci.yml@v1
90+
needs:
91+
- store-reusable-workflow-vars
92+
with:
93+
main-branch: 'master'
94+
python-version: '3.11'
95+
docker-image-name: ${{ needs.store-reusable-workflow-vars.outputs.image-name }}
96+
97+
open-api-publish:
98+
uses: maykinmedia/open-api-workflows/.github/workflows/publish.yml@v1
13599
needs:
100+
- store-reusable-workflow-vars
101+
- open-api-ci
136102
- tests
137-
- docker
138-
139-
name: Push Docker image
140-
runs-on: ubuntu-latest
141-
if: github.event_name == 'push' # exclude PRs
142-
143-
steps:
144-
- uses: actions/checkout@v4
145-
- name: Download built image
146-
uses: actions/download-artifact@v3
147-
with:
148-
name: docker-image
149-
150-
- name: Determine tag
151-
id: vars
152-
run: |
153-
# Strip git ref prefix from version
154-
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
155-
156-
# Strip "v" prefix from tag name (if present at all)
157-
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
158-
159-
# Use Docker `latest` tag convention
160-
[ "$VERSION" == "master" ] && VERSION=latest
161-
162-
echo ::set-output name=tag::${VERSION}
163-
164-
- name: Load image
165-
run: |
166-
docker image load -i image.tar
167-
168-
- name: Log into registry
169-
run: echo "${{ secrets.DOCKER_TOKEN }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
170-
171-
- name: Push the Docker image
172-
env:
173-
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
174-
run: docker push $IMAGE_NAME:$RELEASE_VERSION
103+
with:
104+
docker-image-name: ${{ needs.store-reusable-workflow-vars.outputs.image-name }}
105+
repository-owner: 'maykinmedia'
106+
secrets:
107+
docker-username: ${{ secrets.DOCKER_USERNAME }}
108+
docker-token: ${{ secrets.DOCKER_TOKEN }}

.github/workflows/code-quality.yml

+21-73
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,25 @@
11
name: code-quality
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- '**.py'
9+
- '**.yml'
10+
pull_request:
11+
paths:
12+
- '**.py'
13+
- '**.yml'
14+
workflow_dispatch:
415

516
jobs:
6-
isort:
7-
name: Check import sorting
8-
runs-on: ubuntu-latest
9-
10-
steps:
11-
- uses: actions/checkout@v4
12-
- uses: actions/setup-python@v5
13-
with:
14-
python-version: '3.11'
15-
- uses: isort/isort-action@v1
16-
with:
17-
requirementsFiles: requirements/dev.txt
18-
sortPaths: "src docs"
19-
configuration: '--check-only --diff'
20-
21-
black:
22-
name: Check code formatting with black
23-
runs-on: ubuntu-latest
24-
25-
steps:
26-
- uses: actions/checkout@v4
27-
- uses: actions/setup-python@v5
28-
with:
29-
python-version: '3.11'
30-
- name: Install dependencies
31-
run: |
32-
pip install -r requirements/dev.txt
33-
- name: Run black
34-
run: |
35-
black --check src docs
36-
37-
oas-up-to-date:
38-
name: Check for unexepected OAS changes
39-
runs-on: ubuntu-latest
40-
strategy:
41-
matrix:
42-
version: ['v1', 'v2']
43-
steps:
44-
- uses: actions/checkout@v4
45-
- uses: actions/setup-python@v5
46-
with:
47-
python-version: '3.11'
48-
- uses: actions/setup-node@v4
49-
with:
50-
node-version: '18'
51-
52-
- name: Install system packages
53-
run: |
54-
sudo apt-get update \
55-
&& sudo apt-get install -y --no-install-recommends \
56-
libgdal-dev \
57-
gdal-bin
58-
59-
- name: Install dependencies
60-
run: pip install -r requirements/ci.txt
61-
62-
- name: Generate OAS files
63-
run: ./bin/generate_schema.sh ${{ matrix.version }} openapi-${{ matrix.version }}.yaml
64-
env:
65-
DJANGO_SETTINGS_MODULE: objects.conf.ci
66-
67-
- name: Check for OAS changes
68-
run: |
69-
diff openapi-${{ matrix.version }}.yaml src/objects/api/${{ matrix.version }}/openapi.yaml
70-
- name: Write failure markdown
71-
if: ${{ failure() }}
72-
run: |
73-
echo 'Run the following command locally and commit the changes' >> $GITHUB_STEP_SUMMARY
74-
echo '' >> $GITHUB_STEP_SUMMARY
75-
echo '```bash' >> $GITHUB_STEP_SUMMARY
76-
echo './bin/generate_schema.sh ${{ matrix.version }}' >> $GITHUB_STEP_SUMMARY
77-
echo '```' >> $GITHUB_STEP_SUMMARY
17+
open-api-workflow-code-quality:
18+
uses: maykinmedia/open-api-workflows/.github/workflows/code-quality.yml@v1
19+
with:
20+
apt-packages: 'libgdal-dev gdal-bin'
21+
python-version: '3.11'
22+
node-version: '18'
23+
postgres-image: 'postgis/postgis:12-2.5'
24+
25+
django-settings-module: 'objects.conf.ci'

.github/workflows/codeql-analysis.yml

+2-49
Original file line numberDiff line numberDiff line change
@@ -21,52 +21,5 @@ on:
2121
- cron: '36 0 * * 0'
2222

2323
jobs:
24-
analyze:
25-
name: Analyze
26-
runs-on: ubuntu-latest
27-
permissions:
28-
actions: read
29-
contents: read
30-
security-events: write
31-
32-
strategy:
33-
fail-fast: false
34-
matrix:
35-
language: [ 'javascript', 'python' ]
36-
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37-
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
38-
39-
steps:
40-
- name: Checkout repository
41-
uses: actions/checkout@v4
42-
43-
# Initializes the CodeQL tools for scanning.
44-
- name: Initialize CodeQL
45-
uses: github/codeql-action/init@v2
46-
with:
47-
languages: ${{ matrix.language }}
48-
# If you wish to specify custom queries, you can do so here or in a config file.
49-
# By default, queries listed here will override any specified in a config file.
50-
# Prefix the list here with "+" to use these queries and those in the config file.
51-
52-
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
53-
# queries: security-extended,security-and-quality
54-
55-
56-
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
57-
# If this step fails, then you should remove it and run the build manually (see below)
58-
- name: Autobuild
59-
uses: github/codeql-action/autobuild@v2
60-
61-
# ℹ️ Command-line programs to run using the OS shell.
62-
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
63-
64-
# If the Autobuild fails above, remove it and uncomment the following three lines.
65-
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
66-
67-
# - run: |
68-
# echo "Run, Build Application using script"
69-
# ./location_of_script_within_repo/buildscript.sh
70-
71-
- name: Perform CodeQL Analysis
72-
uses: github/codeql-action/analyze@v2
24+
open-api-workflow-code-analysis:
25+
uses: maykinmedia/open-api-workflows/.github/workflows/code-analysis.yml@v1

.github/workflows/generate-postman-collection.yml

+8-18
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,13 @@ on:
1010
workflow_dispatch:
1111

1212
jobs:
13-
run:
14-
runs-on: ubuntu-latest
13+
open-api-workflow-generate-postman-collection:
14+
uses: maykinmedia/open-api-workflows/.github/workflows/generate-postman-collection.yml@v1
1515
strategy:
1616
matrix:
17-
version: ['v1', 'v2']
18-
19-
name: Run with version ${{ matrix.version }}
20-
21-
steps:
22-
- uses: actions/checkout@v4
23-
- name: Use Node.js
24-
uses: actions/setup-node@v4
25-
with:
26-
node-version: '18'
27-
- name: Install dependencies
28-
run: npm install -g openapi-to-postmanv2
29-
- name: Create tests folder
30-
run: mkdir -p ./tests/postman
31-
- name: Generate Postman collection
32-
run: openapi2postmanv2 -s ./src/objects/api/${{ matrix.version }}/openapi.yaml -o ./tests/postman/collection.json --pretty
17+
version:
18+
- v2
19+
- v1
20+
with:
21+
node-version: '18'
22+
schema-path: 'src/objects/api/${{ matrix.version }}/openapi.yaml'

0 commit comments

Comments
 (0)