Skip to content

Commit 4091f08

Browse files
authored
ci: fix concurrency groups and cleanup only when PR is closed or merged (#383)
*Issue #, if available:* *Description of changes:* Sometimes the integration tests would fail if multiple commits were added at the same time. This is due to each commit cleaning up the functions, while the next commit needed them or deployed them again. The fix is to set up better concurrency groups, and also to only cleanup functions/logs when the PR is closed/merged instead of as part of the integ test. This makes it possible to inspect the execution in the console while the PR is still active to help with debugging or other reasons. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent c87f06d commit 4091f08

File tree

5 files changed

+185
-148
lines changed

5 files changed

+185
-148
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ permissions:
1111

1212
# Cancel when pull request is updated
1313
concurrency:
14-
group: ${{ github.head_ref }}-${{ github.run_id}}
14+
group: ${{ github.head_ref || github.ref_name || github.run_id }}
1515
cancel-in-progress: true
1616

1717
jobs:
@@ -75,59 +75,3 @@ jobs:
7575
with:
7676
node-version: ${{ matrix.node-version }}
7777
secrets: inherit
78-
79-
cleanup-integration-tests:
80-
needs: [integration-tests]
81-
runs-on: ubuntu-latest
82-
permissions:
83-
contents: read
84-
id-token: write
85-
86-
concurrency:
87-
group: ${{ github.head_ref }}-${{ github.run_id }}-${{ matrix.node-version }}-integ
88-
cancel-in-progress: true
89-
90-
strategy:
91-
# Clean up functions sequentially to avoid throttling
92-
max-parallel: 1
93-
fail-fast: false
94-
matrix:
95-
node-version: ["22.x", "24.x"]
96-
97-
if: ${{ !failure() }}
98-
99-
steps:
100-
- uses: actions/checkout@v4
101-
102-
- name: Setup Node.js
103-
uses: actions/setup-node@v4
104-
with:
105-
node-version: ${{ matrix.node-version }}
106-
cache: "npm"
107-
108-
- name: Download build artifacts
109-
uses: actions/download-artifact@v4
110-
with:
111-
name: built-artifacts
112-
path: .
113-
114-
- name: Install dependencies
115-
run: |
116-
npm ci
117-
118-
- name: Get AWS Credentials
119-
id: credentials
120-
if: github.actor != 'nektos/act'
121-
uses: aws-actions/configure-aws-credentials@v4
122-
with:
123-
role-to-assume: "${{ secrets.ACTIONS_INTEGRATION_ROLE_NAME }}"
124-
role-session-name: githubIntegrationTest
125-
aws-region: ${{ vars.AWS_REGION }}
126-
127-
- name: Cleanup Lambda functions
128-
env:
129-
LAMBDA_ENDPOINT: ${{ secrets.LAMBDA_ENDPOINT }}
130-
GITHUB_EVENT_NAME: ${{ github.event_name }}
131-
GITHUB_EVENT_NUMBER: ${{ github.event.number }}
132-
run: |
133-
node .github/workflows/scripts/integration-test/integration-test.js --cleanup-only --runtime ${{ matrix.node-version }}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: Cleanup Integration Tests
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- main
8+
9+
permissions:
10+
contents: read # This is required for actions/checkout
11+
12+
# Concurrency group for build.yml. This will cancel the cleanup workflow if a new build
13+
# for the same branch starts
14+
concurrency:
15+
group: ${{ github.head_ref || github.ref_name || github.run_id }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- name: Setup Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: "24.x"
30+
cache: "npm"
31+
32+
- name: Install dependencies
33+
run: npm ci
34+
35+
- name: Build project
36+
run: npm run build
37+
38+
- name: Upload build artifacts
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: built-artifacts
42+
path: |
43+
packages/**/dist*/*
44+
package.json
45+
package-lock.json
46+
47+
cleanup-integration-tests:
48+
needs: build
49+
runs-on: ubuntu-latest
50+
permissions:
51+
contents: read
52+
id-token: write
53+
54+
concurrency:
55+
# Concurrency group for integration-test.yml. This will cancel the cleanup if integration tests start for the same branch.
56+
group: ${{ github.head_ref || github.ref_name || github.run_id }}-${{ matrix.node-version }}-integ
57+
cancel-in-progress: true
58+
59+
strategy:
60+
max-parallel: 1
61+
fail-fast: false
62+
matrix:
63+
node-version: ["22.x", "24.x"]
64+
65+
steps:
66+
- uses: actions/checkout@v4
67+
68+
- name: Setup Node.js
69+
uses: actions/setup-node@v4
70+
with:
71+
node-version: "24.x"
72+
cache: "npm"
73+
74+
- name: Download build artifacts
75+
uses: actions/download-artifact@v4
76+
with:
77+
name: built-artifacts
78+
path: .
79+
80+
- name: Install dependencies
81+
run: npm ci
82+
83+
- name: Get AWS Credentials for function scrubber
84+
id: credentials
85+
if: github.actor != 'nektos/act'
86+
uses: aws-actions/configure-aws-credentials@v4
87+
with:
88+
role-to-assume: "${{ secrets.ACTIONS_INTEGRATION_ROLE_NAME }}"
89+
role-session-name: githubIntegrationTest
90+
aws-region: ${{ vars.AWS_REGION }}
91+
92+
- name: Cleanup Lambda functions
93+
env:
94+
LAMBDA_ENDPOINT: ${{ secrets.LAMBDA_ENDPOINT }}
95+
GITHUB_EVENT_NAME: "pull_request"
96+
GITHUB_EVENT_NUMBER: ${{ github.event.pull_request.number }}
97+
run: |
98+
node .github/workflows/scripts/integration-test/integration-test.js --cleanup-only --runtime ${{ matrix.node-version }}
99+
100+
- name: Install awscurl
101+
run: pip install awscurl
102+
103+
- name: Get AWS Credentials for log scrubber
104+
id: log-credentials
105+
if: github.actor != 'nektos/act'
106+
uses: aws-actions/configure-aws-credentials@v4
107+
with:
108+
role-to-assume: "${{ secrets.ACTIONS_WEBHOOK_ROLE_ARN }}"
109+
role-session-name: "GitHub-PR-${{ github.event.pull_request.number }}-Cleanup"
110+
aws-region: ${{ vars.AWS_REGION }}
111+
112+
# TODO: move the logic for this into this repo and also delete logs for main branch
113+
- name: Cleanup PR log group
114+
run: |
115+
awscurl --service execute-api \
116+
--region ${{ vars.AWS_REGION }} \
117+
-X POST \
118+
-H "Content-Type: application/json" \
119+
-d '{"logGroupSuffix": "-NodeJS-PR-${{ github.event.pull_request.number }}"}' \
120+
"${{ secrets.LOG_GROUP_CLEANUP_WEBHOOK }}"

.github/workflows/cleanup-pr-logs.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

.github/workflows/integration-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
# Cancel when pull request is updated for this node version
1111
concurrency:
12-
group: ${{ github.head_ref }}-${{ github.run_id }}-${{ inputs.node-version }}-integ
12+
group: ${{ github.head_ref || github.ref_name || github.run_id }}-${{ inputs.node-version }}-integ
1313
cancel-in-progress: true
1414

1515
jobs:

0 commit comments

Comments
 (0)