Skip to content

Commit

Permalink
CI: fix rebasing Test random 💯 (ivan-hc#1330)
Browse files Browse the repository at this point in the history
  • Loading branch information
zen0bit authored Feb 5, 2025
2 parents de0f024 + 7ccea50 commit 5ec349d
Showing 1 changed file with 109 additions and 28 deletions.
137 changes: 109 additions & 28 deletions .github/workflows/test-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ on:
- .github/workflows/test-apps.yml

#pull_request:
# if: github.event.pull_request.head.repo.full_name != github.repository
# branches: main
# paths: 'programs/x86_64/**'
# paths:
# - 'programs/x86_64/**'
# - .github/workflows/test-apps.yml

workflow_dispatch:
inputs:
reset_stats:
description: "RESET stats"
required: true
default: "false"
type: boolean

schedule:
- cron: '0 23 * * *'
Expand All @@ -28,42 +37,102 @@ permissions:
contents: write

jobs:
update-testing-branch:
rebase-testing-branch:
name: "prepare 💤"
runs-on: ubuntu-22.04

steps:
- name: "Check out repository"
- name: "Checkout repository"
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: "Git Config"
run: |
git config user.name "GitHub Actions Bot"
git config user.email "actions@github.com"
git config --global user.name "ivan-hc"
git config --global user.email "noreply@github.com"
- name: "Merge main in testing if needed"
- name: "Check if histories differ"
id: check_history
run: |
git fetch origin main
git fetch origin testing || echo "Branch 'testing' does not exist, creating a new one."
if ! git show-ref --verify --quiet refs/heads/testing; then
git checkout -b testing origin/main
git fetch origin main testing || echo "Branch 'testing' does not exist."
if ! git ls-remote --exit-code --heads origin testing; then
echo "Creating remote 'testing' branch from 'main'..."
git push origin main:testing
echo "RESET_REQUIRED=true" >> $GITHUB_ENV
else
git checkout testing
if git merge-base --is-ancestor origin/main origin/testing; then
echo "Histories are compatible, rebase only."
echo "RESET_REQUIRED=false" >> $GITHUB_ENV
else
echo "Histories are different, reset needed."
echo "RESET_REQUIRED=true" >> $GITHUB_ENV
fi
fi
git fetch origin main
if [[ $(git rev-list HEAD...origin/main --count) -gt 0 ]]; then
echo "Changes detected between 'main' and 'testing'. Merging..."
git merge origin/main --no-edit
git push origin testing
- name: "Reset testing branch if needed"
if: env.RESET_REQUIRED == 'true'
run: |
echo "Resetting testing branch..."
git checkout -B testing origin/testing || git checkout -B testing origin/main
if [[ "${{ github.event.inputs.reset_stats }}" != "true" ]]; then
echo "Preserving test files..."
mkdir -p backup
cp -r tested.list failed.list logs backup/ 2>/dev/null || true
git reset --hard origin/main
mv backup/tested.list backup/failed.list backup/logs . 2>/dev/null || true
rm -rf backup
git add .
git commit -m "update results"
else
echo "Resetting stats..."
echo "Resetting stats" >> $GITHUB_STEP_SUMMARY
git reset --hard origin/main
fi
if [[ $GITHUB_REF == refs/pull/* ]]; then
echo "This is Pull Request. No saving results."
git push --force origin HEAD:testing
- name: "Check if testing differs from main"
id: check_diff
run: |
git fetch origin main testing
if git diff --quiet origin/main..origin/testing; then
echo "No difference between testing and main. Exiting."
echo "skip=true" >> $GITHUB_ENV
else
echo "skip=false" >> $GITHUB_ENV
fi
- name: "Get last commit from testing"
id: last_commit
if: env.skip == 'false'
run: |
LAST_COMMIT=$(git log origin/testing --format=%H -n 1)
echo "Last commit: $LAST_COMMIT"
echo "LAST_COMMIT=$LAST_COMMIT" >> $GITHUB_ENV
- name: "Rebase testing on main"
if: env.skip == 'false'
run: |
git checkout testing
git rebase origin/main
- name: "Reapply last commit"
if: env.skip == 'false'
run: |
if [[ "$LAST_COMMIT" == 'update results' ]]; then
git cherry-pick $LAST_COMMIT
elif [[ "$LAST_COMMIT" != 'update results' ]]; then
echo "Commit from main branch?"
fi
- name: Push changes back to testing
if: env.skip == 'false'
run: |
git push origin testing --force
show-stats:
name: "stats 📝"
runs-on: ubuntu-22.04
needs: update-testing-branch
needs: rebase-testing-branch

steps:
- name: "Check out main branch (for programs count) 🏃"
Expand Down Expand Up @@ -104,7 +173,7 @@ jobs:
generate-matrix:
name: "matrix 🌀"
needs: update-testing-branch
needs: rebase-testing-branch
runs-on: ubuntu-22.04
outputs:
skip: ${{ steps.set-matrix.outputs.skip }}
Expand Down Expand Up @@ -135,7 +204,7 @@ jobs:
fi
if [[ -f failed.list ]]; then
comm -23 totest_tmp.list failed.list > totest.list
echo "Excluding failed:" >> $GITHUB_STEP_SUMMARY
echo "### Excluding failed:" >> $GITHUB_STEP_SUMMARY
cat failed.list >> $GITHUB_STEP_SUMMARY
if [ ! -s totest.list ]; then
echo " 🏁 Nothing to test 🏁" >> $GITHUB_STEP_SUMMARY
Expand All @@ -145,7 +214,7 @@ jobs:
else
mv totest_tmp.list totest.list
fi
FILES=$(shuf -n 100 totest.list || cat totest.list)
FILES=$(shuf -n 100 totest.list | sort || cat totest.list | sort)
MATRIX="{\"include\": ["
for file in $FILES; do
MATRIX+="{\"file\": \"$file\"},"
Expand Down Expand Up @@ -281,8 +350,8 @@ jobs:
- name: "Git Config"
if: always()
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "ivan-hc"
git config --global user.email "noreply@github.com"
- name: "Aggregate and push results"
if: always()
Expand Down Expand Up @@ -313,14 +382,23 @@ jobs:
else
echo "Nothing failed? Great!"
fi
LAST_COMMIT_MSG=$(git log -1 --pretty=%B)
if git diff --cached --quiet; then
echo "No changes to commit?"
else
if [[ $GITHUB_REF == refs/pull/* ]]; then
echo "This is Pull Request. No saving results."
else
elif [[ "${{ github.event.inputs.reset_stats }}" == "true" ]]; then
echo "stats resetted"
git commit -m "update results"
git push origin testing
elif [[ "$LAST_COMMIT_MSG" == "update results" ]]; then
echo "Last commit is 'update results'."
git commit --amend -m "update results"
git push --force origin testing
else
git commit -m "update results"
git push --force origin testing
fi
fi
Expand All @@ -331,7 +409,10 @@ jobs:
failed=$(wc -l < failed.list 2>/dev/null || echo 0)
fail=$(wc -l < fail.list 2>/dev/null || echo "0")
count=$(find programs/x86_64/ -type f | wc -l)
remaining=$((count - tested))
remaining=$((count - tested - failed - fail))
if (( remaining < 0 )); then
remaining=0
fi
echo "### 🏁 $tested tested" >> $GITHUB_STEP_SUMMARY
echo "## 🛅 $remaining to test" >> $GITHUB_STEP_SUMMARY
echo "😱 $failed fails listed" >> $GITHUB_STEP_SUMMARY
Expand Down Expand Up @@ -378,7 +459,7 @@ jobs:
echo "Successfully deleted $DELETED artifacts."
already-tested:
name: "all tested"
name: "all 🏁"
runs-on: ubuntu-22.04
needs: generate-matrix
if: ${{ needs.generate-matrix.outputs.skip == 'true' }}
Expand Down

0 comments on commit 5ec349d

Please sign in to comment.