From 6065f14d61ce10df44364b236ba637f4b6fde457 Mon Sep 17 00:00:00 2001 From: Yourim Cha Date: Fri, 28 Feb 2025 15:49:06 +0900 Subject: [PATCH 1/2] Store benchmark results in branch instead of cache --- .github/workflows/ci.yml | 68 ++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 97b173b08..103623626 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -109,24 +109,17 @@ jobs: with: go-version: ${{ env.GO_VERSION }} - - name: Check out code + - name: Checkout current repository uses: actions/checkout@v4 + with: + path: repo - - name: Stack - run: docker compose -f build/docker/docker-compose.yml up --build -d - - - name: Bench - id: curr-bench - run: | - make bench - content=$(cat output.txt | jq -R -s .) - echo "BENCH_RESULT=$content" >> $GITHUB_OUTPUT - - - name: Set up cache - uses: actions/cache@v3 + - name: Checkout benchmark branch + uses: actions/checkout@v4 with: - path: ./cache - key: ${{ runner.os }}-benchmark + ref: yorkie-ci-benchmark + path: benchmark-repo + continue-on-error: true - name: Read previous benchmark result if: github.event_name == 'pull_request' @@ -135,16 +128,27 @@ jobs: echo "PREV_BENCH_RESULT=null" >> $GITHUB_OUTPUT echo "PREV_COMMIT=null" >> $GITHUB_OUTPUT - if [ -f "./cache/bench_result.txt" ]; then - content=$(cat ./cache/bench_result.txt | jq -R -s .) + if [ -d "benchmark-repo" ] && [ -f "benchmark-repo/bench_result.txt" ]; then + content=$(cat benchmark-repo/bench_result.txt | jq -R -s .) echo "PREV_BENCH_RESULT=$content" >> $GITHUB_OUTPUT - if [ -f "./cache/commit_hash.txt" ]; then - prev_commit=$(cat ./cache/commit_hash.txt) + if [ -f "benchmark-repo/commit_hash.txt" ]; then + prev_commit=$(cat benchmark-repo/commit_hash.txt) echo "PREV_COMMIT=$prev_commit" >> $GITHUB_OUTPUT fi fi + - name: Stack + run: docker compose -f repo/build/docker/docker-compose.yml up --build -d + + - name: Bench + id: curr-bench + run: | + cd repo + make bench + content=$(cat output.txt | jq -R -s .) + echo "BENCH_RESULT=$content" >> $GITHUB_OUTPUT + - name: Trigger n8n webhook if: github.event_name == 'pull_request' run: | @@ -166,12 +170,30 @@ jobs: exit 1 fi - - name: Store benchmark result to cache + - name: Store benchmark result if: github.ref == 'refs/heads/main' run: | - mkdir -p ./cache - cp output.txt ./cache/bench_result.txt - echo "${{ github.sha }}" > ./cache/commit_hash.txt + mkdir -p benchmark-repo + cp repo/output.txt benchmark-repo/bench_result.txt + echo "${{ github.sha }}" > benchmark-repo/commit_hash.txt + + cd benchmark-repo + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + + if [ ! -d ".git" ]; then + git init + git remote add origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} + fi + + git add bench_result.txt + git add commit_hash.txt + TIMESTAMP=$(date -u +"%Y-%m-%d %H:%M:%S UTC") + git diff --staged --quiet || git commit -m "Update benchmark results at $TIMESTAMP" + git checkout -B yorkie-ci-benchmark + git push -f origin yorkie-ci-benchmark + + echo "Benchmark results have been pushed to yorkie-ci-benchmark branch" complex-test: name: complex-test From e6fb642b20db15d77c07eaca2485721c3e2ff8b0 Mon Sep 17 00:00:00 2001 From: Yourim Cha Date: Fri, 28 Feb 2025 16:03:16 +0900 Subject: [PATCH 2/2] Apply coderabbit review --- .github/workflows/ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 103623626..d6397da3d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -131,7 +131,6 @@ jobs: if [ -d "benchmark-repo" ] && [ -f "benchmark-repo/bench_result.txt" ]; then content=$(cat benchmark-repo/bench_result.txt | jq -R -s .) echo "PREV_BENCH_RESULT=$content" >> $GITHUB_OUTPUT - if [ -f "benchmark-repo/commit_hash.txt" ]; then prev_commit=$(cat benchmark-repo/commit_hash.txt) echo "PREV_COMMIT=$prev_commit" >> $GITHUB_OUTPUT @@ -178,8 +177,8 @@ jobs: echo "${{ github.sha }}" > benchmark-repo/commit_hash.txt cd benchmark-repo - git config --global user.name "GitHub Actions" - git config --global user.email "actions@github.com" + git config user.name "GitHub Actions" + git config user.email "actions@github.com" if [ ! -d ".git" ]; then git init