Skip to content

Commit 46a7374

Browse files
GeekTrainerCopilot
andcommitted
Add custom action, reusable workflow, and manual deploy
Module 7: Create setup-python-env composite action and update run-tests.yml to use it in both test-api and test-e2e jobs. Module 8: Extract deploy logic into reusable-deploy.yml, update azure-dev.yml to call it, and add manual-deploy.yml for rollbacks. Also update 6-deploy-azure.md with Bicep file descriptions, corrected line reference, azd pipeline config prompts table, and azd show step. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c02c125 commit 46a7374

6 files changed

Lines changed: 123 additions & 47 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: 'Setup Python Environment'
2+
description: 'Sets up Python, installs dependencies, and seeds the test database'
3+
4+
inputs:
5+
python-version:
6+
description: 'Python version to use'
7+
required: false
8+
default: '3.14'
9+
database-path:
10+
description: 'Path to the test database file'
11+
required: false
12+
default: './test_dogshelter.db'
13+
14+
outputs:
15+
database-file:
16+
description: 'Path to the seeded database file'
17+
value: ${{ steps.seed.outputs.database-file }}
18+
19+
runs:
20+
using: 'composite'
21+
steps:
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: ${{ inputs.python-version }}
26+
27+
- name: Install dependencies
28+
run: pip install -r server/requirements.txt
29+
shell: bash
30+
31+
- name: Seed the database
32+
id: seed
33+
run: python server/utils/seed_test_database.py
34+
shell: bash
35+
env:
36+
DATABASE_PATH: ${{ inputs.database-path }}
37+
38+
- name: Set output
39+
run: echo "database-file=${{ inputs.database-path }}" >> $GITHUB_OUTPUT
40+
shell: bash
41+
id: set-output

.github/workflows/azure-dev.yml

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,6 @@ permissions:
1313

1414
jobs:
1515
deploy:
16-
runs-on: ubuntu-latest
1716
if: github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success'
18-
concurrency:
19-
group: deploy-production
20-
cancel-in-progress: false
21-
22-
steps:
23-
- uses: actions/checkout@v4
24-
25-
- name: Install azd
26-
uses: Azure/setup-azd@v2
27-
28-
- name: Log in with Azure (Federated Credentials)
29-
run: |
30-
azd auth login \
31-
--client-id "${{ vars.AZURE_CLIENT_ID }}" \
32-
--federated-credential-provider "github" \
33-
--tenant-id "${{ vars.AZURE_TENANT_ID }}"
34-
35-
- name: Provision and deploy
36-
run: azd up --no-prompt
37-
env:
38-
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
39-
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
40-
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
17+
uses: ./.github/workflows/reusable-deploy.yml
18+
secrets: inherit
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Manual Deploy
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
deploy-ref:
7+
description: 'Git ref to deploy (commit SHA, tag, or branch)'
8+
required: true
9+
default: 'main'
10+
11+
permissions:
12+
id-token: write
13+
contents: read
14+
15+
jobs:
16+
deploy:
17+
uses: ./.github/workflows/reusable-deploy.yml
18+
with:
19+
deploy-ref: ${{ inputs.deploy-ref }}
20+
secrets: inherit
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Reusable Deploy Workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
deploy-ref:
7+
description: 'Git ref to deploy (commit SHA, tag, or branch). Defaults to the caller workflow ref.'
8+
required: false
9+
type: string
10+
default: ''
11+
12+
jobs:
13+
deploy:
14+
runs-on: ubuntu-latest
15+
concurrency:
16+
group: deploy-production
17+
cancel-in-progress: false
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
with:
22+
ref: ${{ inputs.deploy-ref || github.sha }}
23+
24+
- name: Install azd
25+
uses: Azure/setup-azd@v2
26+
27+
- name: Log in with Azure (Federated Credentials)
28+
run: |
29+
azd auth login \
30+
--client-id "${{ vars.AZURE_CLIENT_ID }}" \
31+
--federated-credential-provider "github" \
32+
--tenant-id "${{ vars.AZURE_TENANT_ID }}"
33+
34+
- name: Deploy application
35+
run: azd up --no-prompt
36+
env:
37+
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
38+
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
39+
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}

.github/workflows/run-tests.yml

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,30 @@ jobs:
2020
steps:
2121
- uses: actions/checkout@v4
2222

23-
- name: Set up Python ${{ matrix.python-version }}
24-
uses: actions/setup-python@v5
23+
- name: Setup Python environment
24+
id: seed
25+
uses: ./.github/actions/setup-python-env
2526
with:
2627
python-version: ${{ matrix.python-version }}
27-
cache: 'pip'
28-
29-
- name: Install dependencies
30-
run: |
31-
python -m pip install --upgrade pip
32-
pip install -r server/requirements.txt
28+
database-path: ${{ vars.TEST_DATABASE_PATH }}
3329

3430
- name: Run tests
31+
run: python -m unittest test_app -v
3532
working-directory: ./server
36-
run: |
37-
python -m unittest test_app -v
33+
env:
34+
DATABASE_PATH: ${{ steps.seed.outputs.database-file }}
3835

3936
test-e2e:
4037
runs-on: ubuntu-latest
4138

4239
steps:
4340
- uses: actions/checkout@v4
4441

45-
- name: Set up Python
46-
uses: actions/setup-python@v5
42+
- name: Setup Python environment
43+
id: seed
44+
uses: ./.github/actions/setup-python-env
4745
with:
48-
python-version: '3.14'
49-
cache: 'pip'
50-
51-
- name: Install Python dependencies
52-
run: |
53-
python -m pip install --upgrade pip
54-
pip install -r server/requirements.txt
46+
database-path: ${{ vars.TEST_DATABASE_PATH }}
5547

5648
- name: Set up Node.js
5749
uses: actions/setup-node@v4
@@ -71,3 +63,5 @@ jobs:
7163
- name: Run e2e tests
7264
working-directory: ./client
7365
run: npx playwright test
66+
env:
67+
DATABASE_PATH: ${{ steps.seed.outputs.database-file }}

content/github-actions/6-deploy-azure.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,15 @@ When you said **yes** to `azd pipeline config`'s commit prompt, it pushed your c
203203
1. Navigate to the **Actions** tab. The push will trigger the **Run Tests** workflow first.
204204
2. Once tests complete successfully, the **Deploy App** workflow will start automatically (via the `workflow_run` trigger).
205205
3. Watch the deploy job run — it will provision Azure resources and deploy both the client and server applications.
206-
4. Once the deployment completes, expand the **Provision and deploy** step logs to find the application URLs.
207-
5. Open the client URL in your browser — you should see the pet shelter application live!
206+
4. Once the deployment completes return to your codespace.
207+
5. Run the following in the terminal to list the details of your new Azure environment:
208208
209-
> [!TIP]
210-
> You can also find your deployment URLs by running `azd show` in the terminal.
209+
```bash
210+
azd show
211+
```
212+
213+
6. Look for the **client** service endpoint in the output.
214+
7. Open the client URL in your browser — you should see the pet shelter application live!
211215
212216
## Summary and next steps
213217

0 commit comments

Comments
 (0)