Skip to content

Update update_commit.py #27

Update update_commit.py

Update update_commit.py #27

name: Fetch Latest Commit and Extract Filename
on:
push:
branches:
- main
jobs:
extract-filename:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Fetch the latest commit from the repository
run: |
# Fetch the latest commit data with the changed files
COMMIT_DATA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/commits?sha=main&per_page=1")
# Debugging: output the full commit data
echo "Commit Data: $COMMIT_DATA"
# Check if the commit data was retrieved successfully
if [ -z "$COMMIT_DATA" ]; then
echo "Error: No commit data received" >&2
exit 1
fi
# Extract the filenames of changed files from the commit
CHANGED_FILES=$(echo $COMMIT_DATA | jq -r '.[0].files[].filename')
# Find the .md file in the list of changed files
FILE_NAME=$(echo "$CHANGED_FILES" | grep -oP '\d{2}\(.*\).md' | head -n 1)
# Debugging: output the extracted filename
echo "Extracted Filename: $FILE_NAME"
# Check if a valid filename was extracted
if [ -z "$FILE_NAME" ]; then
echo "Error: No filename found in changed files" >&2
exit 1
fi
# Set an output to pass to the next step
echo "FILE_NAME=$FILE_NAME" >> $GITHUB_ENV
- name: Use extracted filename in next step
run: |
# Access the extracted filename
echo "The extracted filename is: $FILE_NAME"