-
Notifications
You must be signed in to change notification settings - Fork 0
76 lines (63 loc) · 2.35 KB
/
main.yml
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
name: Build & deploy main
on:
push:
branches:
- main
workflow_dispatch:
permissions:
checks: write
deployments: write
packages: write
pull-requests: write
jobs:
package:
name: Package application
uses: ./.github/workflows/package.yml
secrets: inherit
check_environments:
name: Check environment deployments
runs-on: ubuntu-latest
outputs:
deploy_preprod: ${{ steps.check_preprod_deployment.outputs.deploy_preprod }}
steps:
- uses: actions/github-script@v7
id: check_preprod_deployment
with:
script: |
// If the current pre-prod deployment is not main then we don't want to overwrite it
const { owner, repo } = context.repo;
const preprodEnvironmentName = "pre-production_aks";
const deployments = await github.rest.repos.listDeployments({ owner, repo, environment: preprodEnvironmentName, per_page: 1 });
const lastDeploymentBranch = deployments.data[0].ref;
let deployPreprod = true;
if (lastDeploymentBranch !== "main") {
const branches = await github.rest.repos.listBranches({ owner, repo });
if (branches.data.map(b => b.name).includes(lastDeploymentBranch)) {
deployPreprod = false;
core.info(`${preprodEnvironmentName} has a non-main branch deployed`);
}
}
core.setOutput("deploy_preprod", deployPreprod);
deploy_test:
name: Deploy test environment
needs: [package]
uses: ./.github/workflows/deploy-test.yml
with:
docker_image: ${{ needs.package.outputs.docker_image }}
secrets: inherit
deploy_preprod:
name: Deploy pre-production environment
needs: [package, deploy_test, check_environments]
if: needs.check_environments.outputs.deploy_preprod == 'true'
uses: ./.github/workflows/deploy-preprod.yml
with:
docker_image: ${{ needs.package.outputs.docker_image }}
secrets: inherit
deploy_prod:
name: Deploy production environment
needs: [package, deploy_preprod]
if: always() && (needs.deploy_preprod.result == 'success' || needs.deploy_preprod.result == 'skipped') && (needs.package.result == 'success')
uses: ./.github/workflows/deploy-prod.yml
with:
docker_image: ${{ needs.package.outputs.docker_image }}
secrets: inherit