Skip to content

Commit c3fd8d3

Browse files
ARCH-2091 - Fix im-run-validate-deployed-terraform.yml
Update im-run-validate-deployed-terraform.yml to identify releases with im-open/get-github-deployments. It can't find the values from issues anymore since we've moved away from deployment-board.
1 parent 4acf5b1 commit c3fd8d3

File tree

1 file changed

+26
-43
lines changed

1 file changed

+26
-43
lines changed

workflow-templates/im-run-validate-deployed-terraform.yml

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Workflow Code: ShinySQUIRREL_v26 DO NOT REMOVE
1+
# Workflow Code: ShinySQUIRREL_v27 DO NOT REMOVE
22
# Purpose:
33
# Validates that the deployed terraform matches what is supposed to be deployed
44
# when it runs at a scheduled time or when someone kicks it off manually.
@@ -26,18 +26,23 @@ on:
2626
workflow_dispatch:
2727

2828
permissions:
29-
# # Required for secretless azure access and deploys
29+
# Required for secretless azure access and deploys
3030
id-token: write
3131
contents: read
32+
actions: read
33+
deployments: read
3234

3335
jobs:
3436
auto-plan-the-tf:
3537
runs-on: im-linux
3638

3739
strategy:
3840
matrix:
39-
# TODO: verify the environment you want this workflow to check
41+
# TODO: verify the environments you want this workflow to check
4042
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]
4146

4247
environment: ${{ matrix.environment }}
4348

@@ -66,54 +71,32 @@ jobs:
6671
working-directory: '${{ env.TF_WORKING_DIR }}'
6772

6873
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+
7084
- name: Determine latest release
7185
id: get-latest
7286
uses: actions/github-script@v7
7387
with:
7488
github-token: ${{ secrets.GITHUB_TOKEN }} # Special per-job token generated by GH for interacting with the repo
7589
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.');
11593
core.setOutput('VERSION', 'main');
94+
return;
11695
}
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);
117100
118101
- name: Checkout Repository
119102
uses: actions/checkout@v4

0 commit comments

Comments
 (0)