-
Notifications
You must be signed in to change notification settings - Fork 4
135 lines (123 loc) · 3.82 KB
/
main.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Main
on:
merge_group:
pull_request:
types: [ assigned, opened, synchronize, reopened, labeled, unlabeled ]
push:
branches:
- main
- v*.*.*
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
labeler:
name: Chart Diff Labeler
permissions:
contents: read
pull-requests: write
runs-on: formance-runner
steps:
- uses: 'actions/checkout@v4'
with:
fetch-depth: 0
- uses: actions/labeler@v5
with:
sync-labels: true
- name: Retrieve chart changes
id: chart_changes
run: |
CHARTS=$(git diff origin/main --stat | grep -oE 'charts/[^/]+/' | sed 's|charts/||;s|/||' | sort -u | jq -R -s -c 'split("\n") | map(select(. != ""))')
echo "Changed charts: $CHARTS"
echo "::set-output name=changed_charts::$CHARTS"
- name: Label PR based on chart changes
if: steps.chart_changes.outputs.changed_charts != ''
uses: actions/github-script@v7
env:
CHARTS: ${{ steps.chart_changes.outputs.changed_charts }}
with:
script: |
const charts = JSON.parse(process.env.CHARTS);
const labels = charts.map(chart => `chart-${chart.trim()}`).filter(label => label.length > 0);
if (labels.length > 0) {
console.log(`Applying labels: ${labels.join(', ')}`);
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: labels
});
} else {
console.log('No charts changed, skipping labeling.');
}
pr_name:
if: github.event_name == 'pull_request'
name: Check PR Title
runs-on: formance-runner
permissions:
statuses: write
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tests:
name: Tests Charts
timeout-minutes: 2
runs-on: formance-runner
needs: chart_any
steps:
- uses: 'actions/checkout@v4'
with:
fetch-depth: 0
- name: Tests
run: earthly +tests
chart_any:
name: Any Chart
timeout-minutes: 1
runs-on: formance-runner
needs: chart_matrix_labels
strategy:
matrix:
chart: ${{ fromJson(needs.chart_matrix_labels.outputs.charts) }}
steps:
- uses: 'actions/checkout@v4'
with:
fetch-depth: 0
- uses: ./.github/actions/helm/anychart
with:
CHART_NAME: ${{ matrix.chart }}
CHART_DIR: charts
chart_matrix_labels:
if: github.event.pull_request.labels != ''
name: Check for Labels
needs: readme
timeout-minutes: 1
runs-on: formance-runner
outputs:
charts: ${{ steps.set-matrix.outputs.charts }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Check for Labels
id: set-matrix
run: |
# Extract labels and filter chart labels
CHART_LABELS=$(echo '${{ toJSON(github.event.pull_request.labels) }}' | jq -r '.[].name | select(startswith("chart-")) | sub("chart-"; "")' | jq -R -s -c 'split("\n") | map(select(. != ""))')
# Set the output to be used in the next job
echo "charts=${CHART_LABELS}"
echo "charts=${CHART_LABELS}" >> $GITHUB_OUTPUT
readme:
name: Readme
timeout-minutes: 1
needs: labeler
runs-on: formance-runner
steps:
- uses: 'actions/checkout@v4'
with:
fetch-depth: 0
- name: Base Earthly action
uses: ./.github/actions/earthly/base
- name: Readme
run: earthly +readme
- name: Dirty
uses: ./.github/actions/github/dirty