Skip to content

Generate weekly report #91

Generate weekly report

Generate weekly report #91

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}"