Automated Formatting Fixes #156
Workflow file for this run
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
name: Add Source Header | |
on: | |
push: | |
paths: | |
- '**/*.rs' # Add paths or file types you want to include | |
pull_request: | |
paths: | |
- '**/*.rs' # Add paths or file types you want to include | |
workflow_dispatch: # Allows manual triggering of the workflow | |
jobs: | |
add-source-header: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
issues: write # If you need to add labels or comments | |
steps: | |
- name: Generate GitHub App Token | |
id: generate_token | |
uses: tibdex/github-app-token@v1 | |
with: | |
app_id: ${{ vars.BTL_ACTIONS_BOT_APP_ID }} | |
private_key: ${{ secrets.BTL_ACTIONS_BOT_PRIVATE_KEY }} | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
token: ${{ steps.generate_token.outputs.token }} | |
- name: Install Python (for running script) | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.x | |
- name: Append Source Header to Files | |
run: | | |
# Define the source header template and comment prefix | |
SOURCE_HEADER=$(cat source-header.txt) | |
COMMENT_PREFIX="// " | |
# Remove trailing whitespace from the source header | |
SOURCE_HEADER=$(echo "$SOURCE_HEADER" | sed 's/[ \t]*$//g') | |
# Comment out the source header | |
SOURCE_HEADER_COMMENTED=$(echo "$SOURCE_HEADER" | sed "s|^|$COMMENT_PREFIX|") | |
# Loop through all Rust source files | |
for FILE in $(find . -name '*.rs'); do | |
# Remove existing header (assume it's the first commented block) | |
sed -i '/^\/\/ /d' "$FILE" | |
# Prepend the new source header | |
echo "$SOURCE_HEADER_COMMENTED" | cat - "$FILE" > temp && mv temp "$FILE" | |
done | |
- name: Check if any files were modified | |
id: changes | |
run: | | |
if [ -n "$(git status --porcelain)" ]; then | |
echo "changes=true" >> $GITHUB_OUTPUT | |
else | |
echo "changes=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Create Pull Request with Source Header Updates | |
if: steps.changes.outputs.changes == 'true' | |
uses: peter-evans/create-pull-request@v4 | |
with: | |
token: ${{ steps.generate_token.outputs.token }} | |
commit-message: "Update source header in source files" | |
branch: source-header-updates | |
title: "Update Source Headers" | |
body: | | |
This pull request updates the source headers in the source files. | |
labels: automated |