-
Notifications
You must be signed in to change notification settings - Fork 54
94 lines (82 loc) · 3.34 KB
/
versionCheck.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
84
85
86
87
88
89
90
91
92
93
94
name: Version Check
on:
pull_request:
types: [opened, edited, synchronize]
jobs:
check-version:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all branches
- name: Fetch base branch
run: git fetch origin +refs/heads/${{ github.event.pull_request.base.ref }}:refs/remotes/origin/${{ github.event.pull_request.base.ref }}
- name: Get list of modified files
id: modified_files
run: |
BASE_REF="${{ github.event.pull_request.base.ref }}"
SHA="${{ github.sha }}"
echo "BASE_REF: $BASE_REF"
echo "SHA: $SHA"
FILES=$(git diff --name-only origin/${BASE_REF} HEAD)
echo "FILES=$FILES" # For debugging
# Use printf to properly handle multiline environment variables
printf "FILES<<EOF\n%s\nEOF\n" "$FILES" >> $GITHUB_ENV
- name: Check version tags and post reminders
id: check_versions
run: |
echo "A"
FILES="${{ env.FILES }}"
echo "B"
echo "FILES=$FILES"
FACETS=$(echo "$FILES" | grep -E '^src/Facets/.*\.sol$')
echo "C"
PERIPHERY=$(echo "$FILES" | grep -E '^src/Periphery/.*\.sol$')
echo "D"
echo "FACETS found: $FACETS"
echo "PERIPHERY found: $PERIPHERY"
if [[ -z "$FACETS" && -z "$PERIPHERY" ]]; then
echo "No facets or periphery contracts found in files modified/added by this PR"
exit 0
fi
env:
FILES: ${{ steps.modified_files.outputs.FILES }}
- name: Post reminder comment
if: steps.check_versions.outputs.MISSING_VERSIONS
uses: actions/github-script@v5
with:
script: |
const MISSING_VERSION_FILES = '${{ steps.check_versions.outputs.MISSING_VERSIONS }}'.split(',');
const body = `Did you forget to update the version in file(s): ${MISSING_VERSION_FILES.join(', ')}?`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
- name: Update PR title with updated version info
if: steps.check_versions.outputs.UPDATED_FILES
uses: actions/github-script@v5
with:
script: |
const UPDATED_FILES = '${{ steps.check_versions.outputs.UPDATED_FILES }}'.split(',');
let prTitle = context.payload.pull_request.title;
for (const file of UPDATED_FILES) {
const fileName = file.split('/').pop().replace('.sol', '');
const fileContent = require('fs').readFileSync(file, 'utf8');
const versionMatch = fileContent.match(/@custom:version\s+([\d.]+)/);
if (versionMatch) {
const version = versionMatch[1];
const versionTag = `${fileName} v${version}`;
if (!prTitle.includes(versionTag)) {
prTitle += ` (${versionTag})`;
}
}
}
github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
title: prTitle
});