|
1 |
| -# Workflow Code: ShinySQUIRREL_v26 DO NOT REMOVE |
| 1 | +# Workflow Code: ShinySQUIRREL_v27 DO NOT REMOVE |
2 | 2 | # Purpose:
|
3 | 3 | # Validates that the deployed terraform matches what is supposed to be deployed
|
4 | 4 | # when it runs at a scheduled time or when someone kicks it off manually.
|
|
26 | 26 | workflow_dispatch:
|
27 | 27 |
|
28 | 28 | permissions:
|
29 |
| - # # Required for secretless azure access and deploys |
| 29 | + # Required for secretless azure access and deploys |
30 | 30 | id-token: write
|
31 | 31 | contents: read
|
| 32 | + actions: read |
| 33 | + deployments: read |
32 | 34 |
|
33 | 35 | jobs:
|
34 | 36 | auto-plan-the-tf:
|
35 | 37 | runs-on: im-linux
|
36 | 38 |
|
37 | 39 | strategy:
|
38 | 40 | matrix:
|
39 |
| - # TODO: verify the environment you want this workflow to check |
| 41 | + # TODO: verify the environments you want this workflow to check |
40 | 42 | environment: [dev, qa, stage, demo, uat, prod]
|
| 43 | + |
| 44 | + # TODO: verify the instances match the possible values used in the im-deploy-* workflows |
| 45 | + instance: [na26, na27] # Other common values are [dev,qa,stage,prod], [primary,secondary] or [slot1,slot2] |
41 | 46 |
|
42 | 47 | environment: ${{ matrix.environment }}
|
43 | 48 |
|
@@ -66,54 +71,32 @@ jobs:
|
66 | 71 | working-directory: '${{ env.TF_WORKING_DIR }}'
|
67 | 72 |
|
68 | 73 | steps:
|
69 |
| - # TODO: SWAT - Need a replacement for determining which release is the latest |
| 74 | + - name: Get GitHub Deployments for Entity |
| 75 | + id: get-deployments |
| 76 | + continue-on-error: true |
| 77 | + uses: im-open/get-github-deployments@v1 |
| 78 | + with: |
| 79 | + entity: '' # TODO: Add the entity name from the 'metadata.name' field in the catalog-info.yml file |
| 80 | + instance: ${{ matrix.instance }} |
| 81 | + environment: ${{ matrix.environment }} |
| 82 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 83 | + |
70 | 84 | - name: Determine latest release
|
71 | 85 | id: get-latest
|
72 | 86 | uses: actions/github-script@v7
|
73 | 87 | with:
|
74 | 88 | github-token: ${{ secrets.GITHUB_TOKEN }} # Special per-job token generated by GH for interacting with the repo
|
75 | 89 | script: |
|
76 |
| - let labelName = `??currently-in-${{ matrix.environment }}`; |
77 |
| - try { |
78 |
| - let owner = context.repo.owner; |
79 |
| - let repo = context.repo.repo; |
80 |
| -
|
81 |
| - core.info(`Finding issues with label '${labelName}'...`); |
82 |
| -
|
83 |
| - const query = ` |
84 |
| - query { |
85 |
| - repository(owner: "${owner}", name: "${repo}") { |
86 |
| - issues(first: 1, filterBy: {labels: ["${labelName}"]}) { |
87 |
| - edges { |
88 |
| - node { |
89 |
| - title |
90 |
| - } |
91 |
| - } |
92 |
| - } |
93 |
| - } |
94 |
| - }`; |
95 |
| -
|
96 |
| - const response = await github.graphql(query); |
97 |
| -
|
98 |
| - if (!response.repository.issues || !response.repository.issues.edges || response.repository.issues.edges.length === 0) { |
99 |
| - core.info(`There were no issues with label '${labelName}'. Default to checking against main.`); |
100 |
| - core.setOutput('VERSION', 'main'); |
101 |
| - } |
102 |
| - else { |
103 |
| - const title = response.repository.issues.edges.map(ri => ri.node.title)[0]; |
104 |
| - core.info(`The following issues had label '${labelName}': '${title}'`); |
105 |
| -
|
106 |
| - const regex = /(branch|tag|sha) Deploy: /i; |
107 |
| - let version = title.replace(regex, '').trim(); |
108 |
| - core.info(`The deployed infrastructure will be compared against ${version}`); |
109 |
| - core.setOutput('VERSION', version); |
110 |
| - } |
111 |
| - } catch (error) { |
112 |
| - core.info(`An error occurred retrieving issues with the '${labelName}' label: ${error}`); |
113 |
| - core.info(`You may need to manually remove the ${labelName} from other issues`); |
114 |
| - core.info('Default to checking tf against main.'); |
| 90 | + const deployments = JSON.parse('${{ steps.get-deployments.outputs.deployments }}'); |
| 91 | + if (!deployments || deployments.length === 0 || !deployments.some(d => d.status === 'SUCCESS')) { |
| 92 | + core.info('No successful deployments found. Defaulting to main.'); |
115 | 93 | core.setOutput('VERSION', 'main');
|
| 94 | + return; |
116 | 95 | }
|
| 96 | + |
| 97 | + const successfulDeployments = deployments.filter(d => d.status === 'SUCCESS').sort((a, b) => new Date(b.created_at) - new Date(a.created_at)); |
| 98 | + const latestDeployment = successfulDeployments[0]; |
| 99 | + core.setOutput('VERSION', latestDeployment.ref); |
117 | 100 |
|
118 | 101 | - name: Checkout Repository
|
119 | 102 | uses: actions/checkout@v4
|
|
0 commit comments