-
Notifications
You must be signed in to change notification settings - Fork 0
36 lines (30 loc) · 1.59 KB
/
modification.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
name: modification
on:
workflow_dispatch:
push:
paths: .github/workflows/modification.yml
jobs:
main:
runs-on: ubuntu-latest
steps:
- name: Run the workflow script
run: |
# Make Bash print the commands as it is executing them
set -x
# Generate new file content by using the current date and time instant
DATE=$(date -Iseconds)
# Build the GitHub API URL using the GitHub Actions `github` context
# https://docs.github.com/en/rest/reference/repos#create-or-update-file-contents
# https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
URL="${{github.api_url}}/repos/${{github.repository}}/contents/artifact"
# Call the GitHub API to fetch the current version's SHA as a base
# Note that `-r` (raw) is used with `jq` to not get string quotes
SHA=$(curl --no-progress-meter -u :${{github.token}} $URL | jq -r .sha)
# Build the JSON payload string to send to the GitHub API endpoint
# https://docs.github.com/en/rest/reference/repos#create-or-update-file-contents
MESSAGE="Update workflow artifact file\n\nThis file was modified using the GitHub Actions workflow."
CONTENT=$(echo $DATE | base64 -w 0)
DATA='{"message":"'$MESSAGE'","content":"'$CONTENT'","sha":"'$SHA'"}'
# Call the GitHub API endpoint using Basic auth with PAT for password
# https://docs.github.com/en/rest/overview/other-authentication-methods#via-oauth-and-personal-access-tokens
curl --no-progress-meter -u :${{github.token}} -X PUT $URL -d "$DATA"