Git action test [AllBridgeFacet v3.0.1] [@coderabbit ignore] #35
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: 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 | |
echo "$FILES" > modified_files.txt # Write filenames to a temporary file | |
- name: Check version tags and post reminders | |
id: check_versions | |
run: | | |
BASE_REF="${{ github.event.pull_request.base.ref }}" | |
FILES=$(cat modified_files.txt) # Read filenames from the temporary file | |
echo "FILES=$FILES" | |
# Initialize variables | |
MISSING_VERSION_TAG=() | |
MISSING_VERSION_UPDATE=() | |
UPDATED_CONTRACTS=() | |
# Process each file separately | |
while IFS= read -r FILE; do | |
if [[ "$FILE" == *.sol ]]; then | |
VERSION_TAG=$(grep -E '^/// @custom:version' "$FILE" || true) | |
# Check if version tag exists | |
if [[ -z "$VERSION_TAG" ]]; then | |
MISSING_VERSION_TAG+=("$FILE") | |
else | |
# Check if version tag was updated in this PR | |
if git diff -U0 origin/${BASE_REF} HEAD "$FILE" | grep -qE '^@@.*\+/// @custom:version'; then | |
CONTRACT_NAME=$(basename "$FILE" .sol) | |
NEW_VERSION=$(echo "$VERSION_TAG" | awk '{print $NF}') | |
UPDATED_CONTRACTS+=("$CONTRACT_NAME $NEW_VERSION") | |
else | |
MISSING_VERSION_UPDATE+=("$FILE") | |
fi | |
fi | |
fi | |
done <<< "$FILES" | |
# Output the results | |
if [[ ${#MISSING_VERSION_TAG[@]} -ne 0 ]]; then | |
echo "Files missing version tags: ${MISSING_VERSION_TAG[*]}" | |
# exit 1 | |
fi | |
if [[ ${#MISSING_VERSION_UPDATE[@]} -ne 0 ]]; then | |
echo "Files with version tags not updated: ${MISSING_VERSION_UPDATE[*]}" | |
# exit 1 | |
fi | |
if [[ ${#UPDATED_CONTRACTS[@]} -ne 0 ]]; then | |
echo "Updated contracts and versions: ${UPDATED_CONTRACTS[*]}" | |
fi | |
- name: Post reminder comment | |
if: steps.check_versions.outputs.MISSING_VERSION_UPDATE | |
uses: actions/github-script@v5 | |
with: | |
script: | | |
const MISSING_VERSION_FILES = '${{ steps.check_versions.outputs.MISSING_VERSION_UPDATE }}'.split(','); | |
const body = `The following files have version tags that were not updated: ${MISSING_VERSION_FILES.join(', ')}. Please update the version tags.`; | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: body | |
}); | |
- name: Post version updates comment | |
if: success() | |
uses: actions/github-script@v5 | |
with: | |
script: | | |
const UPDATED_CONTRACTS = '${{ steps.check_versions.outputs.UPDATED_CONTRACTS }}'.split(','); | |
const body = `The following contracts have been updated with new versions: ${UPDATED_CONTRACTS.join(', ')}.`; | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: body | |
}); |