-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (92 loc) · 3.03 KB
/
generate-weekly-report.yaml
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
name: Generate weekly report
on:
schedule:
# Run on every Friday, at 7am
- cron: '0 7 * * 5'
workflow_dispatch:
inputs:
target_branch:
type: string
required: false
default: master
description: |
The name of a branch with the generated report to be pushed.
jobs:
generate-weekly-report:
runs-on: ubuntu-latest
steps:
- name: Check out reports repo
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
path: reports
- name: Figure out new report date
id: new-report-date
run: |
set -exuo pipefail
echo "date=$(date --date='1 day ago' '+%F')" >>"${GITHUB_OUTPUT}"
- name: Figure out last report date
id: last-report-date
run: |
set -exuo pipefail
cd reports
latest=$(find . -maxdepth 1 -type d -regextype gnu-awk -regex './[0-9]{4}-[0-9]{2}-[0-9]{2}' | sort --reverse | head --lines 1 | cut -f2 -d/)
echo "date=${latest:--}" >>"${GITHUB_OUTPUT}"
- name: Validate dates
id: validate-dates
env:
PREV_DATE: ${{ steps.last-report-date.outputs.date }}
DATE: ${{ steps.new-report-date.outputs.date }}
run: |
set -exuo pipefail
ok=0
if [[ "${PREV_DATE}" = '-' ]]; then
ok=1
elif [[ "${PREV_DATE}" != "${DATE}" ]]; then
old_date=$(printf '%s\n' "${PREV_DATE}" "${DATE}" | sort | head --lines 1)
if [[ "${old_date}" = "${PREV_DATE}" ]]; then
ok=1
fi
fi
echo "ok=${ok}" >>"${GITHUB_OUTPUT}"
- name: Check out scripts repo
if: steps.validate-dates.outputs.ok == 1
uses: actions/checkout@v4
with:
repository: flatcar/scripts
path: scripts
ref: main
fetch-depth: 1000
- name: Check out gentoo repo
if: steps.validate-dates.outputs.ok == 1
uses: actions/checkout@v4
with:
repository: gentoo/gentoo
path: gentoo
ref: master
fetch-depth: 20000
- name: Run reports
if: steps.validate-dates.outputs.ok == 1
env:
# paths are relative to the reports directory
SCRIPTS: ../scripts
GENTOO: ../gentoo
PREV_DATE: ${{ steps.last-report-date.outputs.date }}
DATE: ${{ steps.new-report-date.outputs.date }}
run: |
set -exuo pipefail
cd reports
./run-reports.sh
- name: Push new report
if: steps.validate-dates.outputs.ok == 1
env:
DATE: ${{ steps.new-report-date.outputs.date }}
TARGET_BRANCH: ${{ inputs.target_branch }}
run: |
set -exuo pipefail
cd reports
git config user.name 'Flatcar Buildbot'
git config user.email '[email protected]'
git add "${DATE}"
git commit -m "Report for ${DATE}"
git push origin "HEAD:${TARGET_BRANCH:-master}"