Skip to content

Commit

Permalink
ci: new gha to update rules
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Bandeira <[email protected]>
  • Loading branch information
Vitor Bandeira committed Jul 29, 2024
1 parent db65df4 commit abbc09d
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 98 deletions.
52 changes: 0 additions & 52 deletions .github/workflows/github-actions-manual-update-rules.yml

This file was deleted.

89 changes: 43 additions & 46 deletions .github/workflows/github-actions-update-rules.yml
Original file line number Diff line number Diff line change
@@ -1,71 +1,68 @@
name: Create draft PR for updated rules
name: Update Rules

on:
repository_dispatch:
types:
- set-new-golden
pull_request:
types: [labeled]

jobs:
update:
update-rules:
if: contains(github.event.label.name, 'Update Rules')
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Check out repository code recursively
- name: Check out PR code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Git prep
run: |
git config --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*"
git fetch
git checkout "origin/pr/${{ github.event.client_payload.branch }}"
- uses: actions/setup-python@v4
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 1

- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install Python Packages
run: |
pip install firebase-admin
- name: Query Jenkins Build Status
id: query_jenkins
run: |
.github/workflows/jenkins-check-build.sh "${{ github.event.pull_request.number }}"
- name: Execute Python Script Update
env:
CREDS_FILE: ${{ secrets.CREDS_FILE }}
API_BASE_URL: ${{ secrets.API_BASE_URL }}
run: |
echo ${{ github.event_name }}
echo ${{ github.event.client_payload.type }}
if [[ "${{ github.event_name }}" == "repository_dispatch" && "${{ github.event.client_payload.type }}" == "overwrite" ]]; then
python flow/util/updateRules.py --keyFile "${CREDS_FILE}" --apiURL ${API_BASE_URL} --commitSHA ${{ github.event.client_payload.commitsha }} --overwrite
else
python flow/util/updateRules.py --keyFile "${CREDS_FILE}" --apiURL ${API_BASE_URL} --commitSHA ${{ github.event.client_payload.commitsha }}
set -e
COMMIT_SHA=$(git rev-parse HEAD)
if [[ "${{ github.event.label.name }}" == "Update Rules Overwrite" ]]; then
python flow/util/updateRules.py --keyFile "${CREDS_FILE}" \
--apiURL "${API_BASE_URL}" \
--commitSHA "${COMMIT_SHA}" \
--overwrite
else
python flow/util/updateRules.py --keyFile "${CREDS_FILE}" \
--apiURL "${API_BASE_URL}" \
--commitSHA "${COMMIT_SHA}"
fi
- name: Push updated rules
id: remote-update
- name: Check for changes and commit
id: check-and-commit
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
if [ -n "$(git status --porcelain)" ]; then
echo "has_update=true" >> "$GITHUB_OUTPUT"
git add .
git commit --signoff -m "flow: update rules"
echo "has_update=true" >> "$GITHUB_ENV"
else
echo "has_update=false" >> "$GITHUB_OUTPUT"
echo "has_update=false" >> "$GITHUB_ENV"
fi
git add .
git commit --signoff -m "flow: update rules based on new golden reference"
- if: "github.event.client_payload.branch != 'master'"
name: update rules pr
id: remote-update-pr
- name: Push changes
if: env.has_update == 'true'
run: |
git push origin "HEAD:refs/pull/${{ github.event.client_payload.branch }}/head"
- if: "steps.remote-update.outputs.has_update == 'true' && github.event.client_payload.branch == 'master'"
name: Create Draft PR
uses: peter-evans/create-pull-request@v5
with:
token: ${{ github.token }}
signoff: true
delete-branch: true
title: "[BOT] Update rules"
reviewers: |
vvbandeira
maliberty
draft: true
branch: bot-update-rules
commit-message: |
[BOT] Update rules
git push
59 changes: 59 additions & 0 deletions .github/workflows/jenkins-check-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash

# Check if exactly one argument is provided
if [ "$#" -ne 1 ]; then
echo "Error: Only argument required is the PR number."
exit 1
fi

# Check if the argument is numerical
if ! [[ "$1" =~ ^[0-9]+$ ]]; then
echo "Error: The argument must be a numerical value."
exit 1
fi
PR_NUMBER="$1"

JENKINS_URL="https://jenkins.openroad.tools/job/OpenROAD-flow-scripts-Public"
PR_BUILD_URL="${JENKINS_URL}/job/PR-${PR_NUMBER}-merge"

while true; do

if ! curl -s "${PR_BUILD_URL}/api/json?pretty" | jq . > /dev/null 2>&1 ; then
echo "Error while checking PR ${PR_NUMBER}"
exit 1
fi

echo "Checking if build is in queue..."
in_queue=$(curl -s "${PR_BUILD_URL}/api/json?pretty" | jq -r '.inQueue')
if [ "$in_queue" == "true" ]; then
echo "Build still in queue. Retrying..."
sleep 30
continue
fi
echo "Build not in queue."

echo "Getting latest build ID..."
LAST_BUILD_ID=$(curl -s "${PR_BUILD_URL}/api/json?pretty" | jq -r '.lastBuild.number')
if [ "$LAST_BUILD_ID" == "null" ]; then
echo "Build id is null."
exit 1
fi
if [ -z "$LAST_BUILD_ID" ]; then
echo "No build found. Retrying..."
sleep 30
continue
fi
echo "Latest build id ${LAST_BUILD_ID}"

echo "Checking if build is done..."
BUILD_URL="${PR_BUILD_URL}/${LAST_BUILD_ID}/api/json?pretty"
in_progress=$(curl -s "$BUILD_URL" | jq -r '.inProgress')
if [ "$in_progress" == "false" ]; then
echo "Build complete. Running Python script..."
break
else
echo "Build still in progress. Waiting for completion..."
sleep 30
fi

done

0 comments on commit abbc09d

Please sign in to comment.