-
Notifications
You must be signed in to change notification settings - Fork 2
215 lines (179 loc) · 7.45 KB
/
git_workflow_process.yaml
File metadata and controls
215 lines (179 loc) · 7.45 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
name: Automated Git Workflow used by developers
on:
push:
branches: ['*']
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: write
pull-requests: write
id-token: write
issues: write
jobs:
format-and-create-pr:
runs-on: ubuntu-latest
steps:
- name: Debug Branch Info
run: |
echo "github.ref: ${{ github.ref }}"
echo "github.head_ref: ${{ github.head_ref }}"
echo "repo owner: ${{ github.repository_owner }}"
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref != '' && github.head_ref || github.ref != '' && github.ref || 'main' }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0 # Get full history
- name: Setup Git
run: |
git config user.name "GitHub Actions Bot"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Set up GitHub CLI
run: |
sudo apt-get update && sudo apt-get install -y gh
- name: Authenticate GitHub CLI
run: |
echo "${{ secrets.BFI_BOT_TOKEN }}" | gh auth login --with-token
- name: Run security scans with CodeQL
uses: github/codeql-action/init@v3
with:
languages: python
# - name: Analyze code with CodeQL
# uses: github/codeql-action/analyze@v2
- name: Run Black (format instead of check)
uses: psf/black@stable
with:
options: "."
- name: Run isort (apply changes)
uses: isort/isort-action@v1
with:
requirements-files: ""
sort-paths: "."
configuration: "--profile black"
- name: Check for formatting changes
id: check-changes
run: |
if [[ -n "$(git status --porcelain)" ]]; then
echo "changes=true" >> $GITHUB_OUTPUT
echo "Formatting changes were needed and have been applied"
else
echo "changes=false" >> $GITHUB_OUTPUT
echo "No formatting changes needed"
fi
- name: Commit changes back to branch
if: steps.check-changes.outputs.changes == 'true'
run: |
git add .
git commit -m "Apply automatic formatting with Black and isort"
- name: Check if PR exists
id: check-pr
if: github.event_name == 'push' && github.ref != 'refs/heads/main'
run: |
echo "Checking for PR in datadigipres/checksum_scripts for branch: $BRANCH_NAME"
# Query the GitHub API to check for existing PRs
PR_EXISTS=$(gh pr list \
--repo "bfidatadigipres/checksum_scripts" \
--head "${BRANCH_NAME}" \
--base main \
--state open \
--json number \
--jq 'length' 2>/dev/null || echo "error")
echo "PR_EXISTS raw value: $PR_EXISTS"
if [ "$PR_EXISTS" = "error" ]; then
echo "Error querying GitHub API — assuming no PR exists"
echo "create_pr=true" >> $GITHUB_OUTPUT
elif [ "$PR_EXISTS" -gt 0 ]; then
echo "PR for branch $BRANCH_NAME already exists"
echo "create_pr=false" >> $GITHUB_OUTPUT
else
echo "No PR exists for branch $BRANCH_NAME"
echo "create_pr=true" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{secrets.BFI_BOT_TOKEN}}
BRANCH_NAME: ${{ github.ref_name || github.ref}}
- name: Create PR
if: steps.check-pr.outputs.create_pr == 'true' && github.event_name == 'push' && github.ref != 'refs/heads/main'
run: |
echo "Creating PR for branch $REF_NAME"
gh pr create \
--repo "bfidatadigipres/checksum_scripts" \
--base main \
--head "$REPO_OWNER:$REF_NAME" \
--title "Automated PR for branch: $REF_NAME" \
--body "This PR was automatically created from branch: $REF_NAME" \
env:
GH_TOKEN: ${{secrets.BFI_BOT_TOKEN}}
REPO_OWNER: ${{ github.repository_owner }}
REF_NAME: ${{ github.ref_name }}
lint:
runs-on: ubuntu-latest
needs: format-and-create-pr
steps:
- name: Set up GitHub CLI
run: |
curl -fsSL https://cli.github.com/install.sh | bash
- name: Authenticate GitHub CLI
run: |
unset GH_TOKEN
echo "${{ secrets.BFI_BOT_TOKEN}}" | gh auth login --with-token
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref }}
fetch-depth: 0
- run: git pull
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- run: pip install pylint
- id: pylint
run: |
export LANG=en_US.UTF-8
mkdir -p reports
python -m pylint *.py > reports/pylint-report.txt || true
sed -i 's/\(.*:[0-9]\+:[0-9]\+:[[:space:]]*\)\(E[0-9]\{4\}\)/\1🚨 \2/' reports/pylint-report.txt
sed -i 's/\(.*:[0-9]\+:[0-9]\+:[[:space:]]*\)\(W[0-9]\{4\}\)/\1⚠️ \2/' reports/pylint-report.txt
sed -i 's/\(.*:[0-9]\+:[0-9]\+:[[:space:]]*\)\(I[0-9]\{4\}\)/\1ℹ️ \2/' reports/pylint-report.txt
sed -i 's/\(.*:[0-9]\+:[0-9]\+:[[:space:]]*\)\(C[0-9]\{4\}\)/\1🎨 \2/' reports/pylint-report.txt
sed -i 's/\(.*:[0-9]\+:[0-9]\+:[[:space:]]*\)\(F[0-9]\{4\}\)/\1🛑 \2/' reports/pylint-report.txt
sed -i 's/\(.*:[0-9]\+:[0-9]\+:[[:space:]]*\)\(R[0-9]\{4\}\)/\1♻️ \2/' reports/pylint-report.txt
- name: print file
run: cat reports/pylint-report.txt
- name: Save Pylint report content to an environment file
id: save_report
run: |
{
pylint_report=$(cat reports/pylint-report.txt)
echo "pylint_report<<EOF"
echo "$pylint_report"
echo "EOF"
} >> $GITHUB_ENV
- name: Check if PR exists
id: check-pr
env:
GITHUB_TOKEN: ${{secrets.BFI_BOT_TOKEN}}
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
run: |
echo "Checking for PR on branch: $BRANCH_NAME"
PR_NUMBER=$(gh pr list --repo "bfidatadigipres/checksum_scripts" --head "$BRANCH_NAME" --state open --json number --jq '.[0].number' 2>/dev/null || echo "error")
echo "Found PR number: $PR_NUMBER"
if [ "$PR_NUMBER" != "error" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "number=$PR_NUMBER" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Comment on PR with Full Pylint Report
if: steps.check-pr.outputs.exists == 'true'
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ steps.check-pr.outputs.number }}
edit-mode: replace
repository: bfidatadigipres/checksum_scripts
body: |
**Automated Pylint Report** 🧑💻
Here is the **formatted** Pylint report:
```plaintext
${{ env.pylint_report }}
```
**Note:** 🚨 Errors need immediate attention! ⚠️ Warnings should be reviewed, but are less critical. ℹ️ Information messages are for your reference.
token: ${{ secrets.BFI_BOT_TOKEN }}