-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (71 loc) · 2.43 KB
/
add-source-header.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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: Add Source Header
on:
push:
paths:
- '**/*.rs'
pull_request:
paths:
- '**/*.rs'
workflow_dispatch:
jobs:
add-source-header:
if: |
github.event_name == 'workflow_dispatch' ||
(github.actor != 'github-actions[bot]' &&
github.actor != 'bythelindemans-actions-bot')
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
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