Git action test [AllBridgeFacet v3.0.1] [@coderabbit ignore] #21
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: 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 | |
- name: Fetch all branches | |
run: git fetch --all | |
- 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}) | |
echo "FILES=$FILES" >> GITHUB_ENV | |
- name: Check version tags and post reminders | |
id: check_versions | |
run: | | |
echo "A" | |
FILES="${{ github.steps.modified_files.outputs.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 | |
MISSING_VERSION_UPDATES=() | |
UPDATED_FILES=() | |
CHECK_VERSION() { | |
FILE=$1 | |
if ! git diff -U0 origin/${BASE_REF} HEAD "$FILE" | grep -E '^@@.*@custom:version'; then | |
MISSING_VERSION_UPDATES+=("$FILE") | |
else | |
UPDATED_FILES+=("$FILE") | |
fi | |
} | |
for FILE in $FACETS; do | |
CHECK_VERSION "$FILE" | |
done | |
for FILE in $PERIPHERY; do | |
CHECK_VERSION "$FILE" | |
done | |
if [ ${#MISSING_VERSION_UPDATES[@]} -ne 0 ]; then | |
echo "MISSING_VERSIONS=$(IFS=,; echo "${MISSING_VERSION_UPDATES[*]}")" >> $GITHUB_ENV | |
echo "MISSING_VERSIONS=${MISSING_VERSION_UPDATES[*]}" | |
fi | |
if [ ${#UPDATED_FILES[@]} -ne 0 ]; then | |
echo "UPDATED_FILES=$(IFS=,; echo "${UPDATED_FILES[*]}")" >> $GITHUB_ENV | |
echo "UPDATED_FILES=${UPDATED_FILES[*]}" | |
fi | |
- 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 | |
}); |