Skip to content

Commit d9c9ede

Browse files
committed
ci: add workflow to check semantic pull requests
Signed-off-by: Emilien Escalle <[email protected]>
1 parent 2cf87c4 commit d9c9ede

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

.github/workflows/__test-action-docker-prune-pull-requests-image-tags.yml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,30 @@ jobs:
3434
}
3535
3636
// Generate random PR tag
37-
core.setOutput("tag", `pr-${1 + Math.floor(Math.random() * 210)}`);
37+
let prNumber;
38+
let attempt = 0;
39+
while(!prNumber && attempt < 5) {
40+
attempt++;
41+
prNumber = 1 + Math.floor(Math.random() * 210);
42+
try {
43+
await github.rest.pulls.get({
44+
owner: context.repo.owner,
45+
repo: context.repo.repo,
46+
pull_number: prNumber,
47+
});
48+
} catch (error) {
49+
if (error.status === 404) {
50+
prNumber = null; // PR does not exist, try again
51+
} else {
52+
throw error; // Other errors
53+
}
54+
}
55+
}
56+
if (!prNumber) {
57+
return core.setFailed("Failed to generate a valid pull request number after multiple attempts");
58+
}
59+
60+
core.setOutput("tag", `pr-${prNumber}`);
3861
3962
// Define expected packages
4063
const packages = [
@@ -127,7 +150,7 @@ jobs:
127150
username: ${{ github.repository_owner }}
128151
password: ${{ secrets.GITHUB_TOKEN }}
129152

130-
- name: Generate a image tag that should be deleted
153+
- name: Generate an image tag that should be deleted
131154
env:
132155
BASE_IMAGE: ${{ needs.arrange-verify.outputs.base-image }}
133156
IMAGE_NAME: ${{ env.IMAGE_NAME }}
@@ -143,6 +166,7 @@ jobs:
143166
- id: prune-pull-requests-image-tags
144167
uses: ./actions/docker/prune-pull-requests-image-tags
145168
with:
169+
github-token: ${{ secrets.GITHUB_TOKEN }}
146170
image: ${{ env.IMAGE_NAME }}
147171

148172
assert:
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
name: "Pull Request - Semantic Lint"
3+
4+
on:
5+
pull_request_target:
6+
types:
7+
- opened
8+
- edited
9+
- synchronize
10+
11+
permissions: {}
12+
13+
jobs:
14+
main:
15+
uses: hoverkraft-tech/ci-github-common/.github/workflows/semantic-pull-request.yml@5f11437c716059f30c635f90055060e4ef8b31a0 # 0.28.0
16+
permissions:
17+
contents: write
18+
pull-requests: write

actions/docker/prune-pull-requests-image-tags/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ inputs:
2525
default: "^pr-([0-9]+)(?:-|$)"
2626
github-token:
2727
description: |
28-
GitHub token with the packages:read and packages:delete scopes.
28+
GitHub token with the folowing scopes: `pull-requests:read`, `packages:read` and `packages:delete`.
2929
See https://docs.github.com/en/packages/learn-github-packages/about-permissions-for-github-packages#about-scopes-and-permissions-for-package-registries.
3030
default: ${{ github.token }}
3131

0 commit comments

Comments
 (0)