-
Notifications
You must be signed in to change notification settings - Fork 3
70 lines (68 loc) · 3.23 KB
/
contexts.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
# based on https://docs.github.com/en/actions/learn-github-actions/contexts#example-printing-context-information-to-the-log
name: dump context
on:
# see all at https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#available-events
create:
push:
pull_request:
release:
schedule:
- cron: "51 17 * * 3" # once a week, https://crontab.guru/#51_17_*_*_3
workflow_dispatch:
jobs:
dump_contexts_to_log:
name: ${{ github.event_name }}
runs-on: ubuntu-latest
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# avoid checking out the repository in a detached state
# https://github.com/stefanzweifel/git-auto-commit-action/issues/70
ref: main
- name: Install Dependencies
run: sudo apt-get install --yes jq gron
# BUG: any toJSON with single quotes will cause the echo statements to fail.
# Not sure how to fix this.
#
# Note that the github context includes a token, but it is scrubbed from logs.
# > Before each job begins, GitHub fetches an installation access token for the job.
# > The GITHUB_TOKEN expires when a job finishes or after a maximum of 24 hours.
- name: Dump github context
run: echo '${{ toJSON(github) }}' | gron --no-sort
- name: Dump job context
run: echo '${{ toJSON(job) }}' | gron --no-sort
- name: Dump steps context
run: echo '${{ toJSON(steps) }}' | gron --no-sort
- name: Dump runner context
run: echo '${{ toJSON(runner) }}' | gron --no-sort
- name: Dump strategy context
run: echo '${{ toJSON(strategy) }}' | gron --no-sort
- name: Dump matrix context
run: echo '${{ toJSON(matrix) }}' | gron --no-sort
- name: Dump env context
run: echo '${{ toJSON(env) }}' | gron --no-sort
- name: Dump all contexts to a file
run: |
echo '{"github": ${{ toJSON(github) }},' > contexts.json
echo '"job": ${{ toJSON(job) }},' >> contexts.json
echo '"steps": ${{ toJSON(steps) }},' >> contexts.json
echo '"runner": ${{ toJSON(runner) }},' >> contexts.json
echo '"strategy": ${{ toJSON(strategy) }},' >> contexts.json
echo '"matrix": ${{ toJSON(matrix) }} }' >> contexts.json
jq '.github.token = "***"' contexts.json > contexts/${{ github.event_name }}.json
rm contexts.json
# gron --no-sort option is unstable https://github.com/tomnomnom/gron/issues/102
gron contexts/${{ github.event_name }}.json > contexts/${{ github.event_name }}.gron
gron --no-sort --colorize contexts/${{ github.event_name }}.json
- name: Set current date
run: echo "CURRENT_DATE=$(date --utc --iso)" >> $GITHUB_ENV
- name: Deploy contexts
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "contexts for ${{ github.event_name }} on ${{ env.CURRENT_DATE }}\n\n${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}\n\n[skip ci]"
skip_checkout: false
branch: main