forked from ls1intum/Artemis
-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (83 loc) · 3.09 KB
/
pullrequest-closed.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
name: Pull Request Closed
on:
pull_request_target:
types: [closed]
jobs:
# If a PR is closed the docker image should be deleted to save space
purge-image:
name: Delete image from ghcr.io
runs-on: ubuntu-latest
steps:
- name: Delete image
uses: bots-house/ghcr-delete-image-action@v1.1.0
with:
owner: ${{ github.repository_owner }}
name: artemis
token: ${{ secrets.GH_TOKEN_ADD_TO_PROJECT }}
tag: pr-${{ github.event.pull_request.number }}
untagged-older-than: 28
# If a PR is closed the testserver lock should be removed and corresponding badges updated
process_labels:
name: Process labels
runs-on: ubuntu-latest
outputs:
labels: ${{ steps.process.outputs.labels }}
badges: ${{ steps.process.outputs.badges }}
steps:
- name: Process labels
id: process
uses: actions/github-script@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const labelsToRemove = [];
const labelsToProcess = [];
// Get the PR number
const prNumber = context.payload.pull_request.number;
// Iterate through labels on the PR
for (const label of context.payload.pull_request.labels) {
const labelName = label.name;
const regex = /^lock:artemis-test(\d+)$/;
if (regex.test(labelName)) {
// Extract the part after "lock:" using capture groups
const extractedLabel = labelName.match(regex)[1];
labelsToProcess.push(extractedLabel);
labelsToRemove.push(labelName);
}
}
// Do something with the extracted labels
console.log('Badges to process:', labelsToProcess);
console.log('Labels to remove:', labelsToRemove);
// Use the labelsToRemove array to remove the matching labels
core.setOutput('badges', JSON.stringify(labelsToProcess));
core.setOutput('labels', labelsToRemove.join(', '));
remove_labels:
name: Remove labels
needs: process_labels
runs-on: ubuntu-latest
if: ${{ needs.process_labels.outputs.labels != '' }}
steps:
- name: Remove labels
uses: actions-ecosystem/action-remove-labels@v1
with:
labels: ${{ needs.process_labels.outputs.labels }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update_badges:
name: Update badges
needs: process_labels
runs-on: ubuntu-latest
strategy:
matrix:
badge: ${{ fromJson(needs.process_labels.outputs.badges) }}
if: ${{ needs.process_labels.outputs.labels != '' }}
steps:
- name: Update badge
uses: RubbaBoy/BYOB@v1.3.0
with:
NAME: "artemis-test${{ matrix.badge }}"
LABEL: "artemis-test${{ matrix.badge }}.artemis.cit.tum.de"
STATUS: ${{ github.event.pull_request.head.ref }}
COLOR: green
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}