dump context #139
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |