Skip to content

Commit d648371

Browse files
committed
add workflows
1 parent 828ba1b commit d648371

File tree

5 files changed

+305
-0
lines changed

5 files changed

+305
-0
lines changed

.github/workflows/azure-dev.yml

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Deploy to Azure with azd
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
- cruft/update
9+
10+
# GitHub Actions workflow to deploy to Azure using azd
11+
# To configure required secrets for connecting to Azure, simply run `azd pipeline config`
12+
13+
# Set up permissions for deploying with secretless Azure federated credentials
14+
# https://learn.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-portal%2Clinux#set-up-azure-login-with-openid-connect-authentication
15+
permissions:
16+
id-token: write
17+
contents: read
18+
19+
jobs:
20+
build:
21+
runs-on: ubuntu-latest
22+
outputs:
23+
uri: ${{ steps.output.outputs.uri }}
24+
env:
25+
AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }}
26+
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
27+
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
28+
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v3
32+
33+
- name: Install azd
34+
uses: Azure/[email protected]
35+
36+
- name: Log in with Azure (Federated Credentials)
37+
if: ${{ env.AZURE_CLIENT_ID != '' }}
38+
run: |
39+
azd auth login `
40+
--client-id "$Env:AZURE_CLIENT_ID" `
41+
--federated-credential-provider "github" `
42+
--tenant-id "$Env:AZURE_TENANT_ID"
43+
shell: pwsh
44+
45+
- name: Log in with Azure (Client Credentials)
46+
if: ${{ env.AZURE_CREDENTIALS != '' }}
47+
run: |
48+
$info = $Env:AZURE_CREDENTIALS | ConvertFrom-Json -AsHashtable;
49+
Write-Host "::add-mask::$($info.clientSecret)"
50+
51+
azd auth login `
52+
--client-id "$($info.clientId)" `
53+
--client-secret "$($info.clientSecret)" `
54+
--tenant-id "$($info.tenantId)"
55+
shell: pwsh
56+
env:
57+
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
58+
59+
- name: Provision Infrastructure
60+
run: azd provision --no-prompt
61+
env:
62+
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
63+
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
64+
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
65+
66+
- name: Deploy Application
67+
run: azd deploy --no-prompt
68+
env:
69+
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
70+
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
71+
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
72+
73+
- name: Output Deployment URI
74+
id: output
75+
run: |
76+
azd env get-values > .env
77+
source .env
78+
echo "uri=$BACKEND_URI" >> "$GITHUB_OUTPUT"
79+
80+
smoketests:
81+
runs-on: ubuntu-latest
82+
needs: build
83+
steps:
84+
85+
- name: Basic smoke test (curl)
86+
env:
87+
URI: ${{needs.build.outputs.uri}}
88+
run: |
89+
echo "Sleeping 1 minute due to https://github.com/Azure/azure-dev/issues/2669"
90+
sleep 60
91+
curl -sSf $URI
92+
- name: Checkout
93+
uses: actions/checkout@v3
94+
95+
- name: Setup python
96+
uses: actions/setup-python@v4
97+
with:
98+
python-version: 3.12
99+
100+
- name: End-to-end smoke tests (playwright)
101+
env:
102+
URI: ${{needs.build.outputs.uri}}
103+
run: |
104+
python3 -m pip install --upgrade pip
105+
python3 -m pip install -r requirements-dev.txt
106+
python3 -m playwright install chromium --with-deps
107+
python3 -m pytest --exitfirst src/tests/smoke/smoketests.py --live-server-url $URI

.github/workflows/cruft.yml

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Update repository with Cruft
2+
permissions:
3+
contents: write
4+
pull-requests: write
5+
on:
6+
workflow_dispatch:
7+
schedule:
8+
- cron: "0 2 * * 1" # Every Monday at 2am
9+
jobs:
10+
update:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: true
14+
matrix:
15+
include:
16+
- add-paths: .
17+
body: Use this to merge the changes to this repository.
18+
branch: cruft/update
19+
commit-message: "chore: accept new Cruft update"
20+
title: New updates detected with Cruft
21+
- add-paths: .cruft.json
22+
body: Use this to reject the changes in this repository.
23+
branch: cruft/reject${{ github.run_id }}
24+
commit-message: "chore: reject new Cruft update"
25+
title: Reject new updates detected with Cruft
26+
steps:
27+
- uses: actions/checkout@v3
28+
29+
- uses: actions/setup-python@v4
30+
with:
31+
python-version: "3.12"
32+
33+
- name: Install Cruft
34+
run: pip3 install -r requirements-dev.txt
35+
36+
- name: Check if update is available
37+
continue-on-error: false
38+
id: check
39+
run: |
40+
CHANGES=0
41+
if [ -f .cruft.json ]; then
42+
if ! cruft check; then
43+
CHANGES=1
44+
fi
45+
else
46+
echo "No .cruft.json file"
47+
fi
48+
49+
echo "has_changes=$CHANGES" >> "$GITHUB_OUTPUT"
50+
51+
- name: Run update if available
52+
if: steps.check.outputs.has_changes == '1'
53+
run: |
54+
git config --global user.email "[email protected]"
55+
git config --global user.name "GitHub"
56+
57+
cruft update --skip-apply-ask --refresh-private-variables
58+
git restore --staged .
59+
60+
- name: Create pull request
61+
if: steps.check.outputs.has_changes == '1'
62+
run: |
63+
echo "::set-output name=branch::${{ matrix.branch }}"
64+
echo "::set-output name=commit-message::${{ matrix.commit-message }}"
65+
git checkout -b "${{ matrix.branch }}"
66+
git add ${{ matrix.add-paths }}
67+
git commit -m "${{ matrix.commit-message }}"
68+
git push origin "${{ matrix.branch }}"

.github/workflows/devcontainer-ci.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Check Dev Container
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
paths:
7+
- ".devcontainer/**"
8+
- ".github/workflows/devcontainer-ci.yaml"
9+
pull_request:
10+
branches: [ "main" ]
11+
paths:
12+
- ".devcontainer/**"
13+
- ".github/workflows/devcontainer-ci.yaml"
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
build:
20+
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- uses: actions/checkout@v3
25+
- name: Use Node.js 20.x
26+
uses: actions/setup-node@v3
27+
with:
28+
node-version: 20.x
29+
- run: npm install -g @devcontainers/cli
30+
- run: devcontainer build --config ./.devcontainer/devcontainer.json --workspace-folder "$(pwd)"

.github/workflows/format.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Run Python linter and formatter
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths-ignore:
7+
- '**.md'
8+
- 'lab/**'
9+
- 'assets/**'
10+
11+
pull_request:
12+
branches: [ main ]
13+
paths-ignore:
14+
- '**.md'
15+
- 'lab/**'
16+
- 'assets/**'
17+
18+
jobs:
19+
checks-format:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v3
23+
- uses: actions/setup-python@v4
24+
with:
25+
python-version: 3.12
26+
cache: 'pip'
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install -r requirements-dev.txt
31+
- name: Lint with ruff
32+
run: |
33+
ruff check .
34+
ruff format .

.github/workflows/tests.yml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Run Python E2E tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths-ignore:
7+
- '**.md'
8+
- 'lab/**'
9+
- 'assets/**'
10+
11+
pull_request:
12+
branches: [ main ]
13+
paths-ignore:
14+
- '**.md'
15+
- 'lab/**'
16+
- 'assets/**'
17+
18+
jobs:
19+
test_package:
20+
21+
name: Test ${{ matrix.os }} Python ${{ matrix.python_version }}
22+
runs-on: ${{ matrix.os }}
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
os: ["ubuntu-20.04"]
27+
python_version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
28+
services:
29+
db:
30+
image: mysql:8.2
31+
env:
32+
MYSQL_ROOT_PASSWORD: mysql
33+
MYSQL_DATABASE: relecloud
34+
ports:
35+
- 3306:3306
36+
# needed because the mysql container does not provide a healthcheck
37+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
38+
steps:
39+
- uses: actions/checkout@v3
40+
- name: Setup python
41+
uses: actions/setup-python@v2
42+
with:
43+
44+
python-version: ${{ matrix.python_version }}
45+
architecture: x64
46+
- name: Install dependencies
47+
run: |
48+
python3 -m pip install --upgrade pip
49+
python3 -m pip install -r requirements-dev.txt
50+
playwright install chromium --with-deps
51+
- name: Seed data
52+
run: |
53+
python3 src/manage.py migrate
54+
python3 src/manage.py loaddata src/seed_data.json
55+
env:
56+
MYSQL_HOST: localhost
57+
MYSQL_USER: root
58+
MYSQL_PASS: mysql
59+
MYSQL_DATABASE: relecloud
60+
- name: Run tests
61+
run: python3 -m pytest
62+
env:
63+
MYSQL_HOST: localhost
64+
MYSQL_USER: root
65+
MYSQL_PASS: mysql
66+
MYSQL_DATABASE: relecloud

0 commit comments

Comments
 (0)