From b04405be321b7573745d591c83a7e3d932a1d9d6 Mon Sep 17 00:00:00 2001 From: Thomas Roos Date: Tue, 17 Dec 2024 15:36:51 +0000 Subject: [PATCH] github workflows: backport from master-next --- .github/workflows/build-test-all-branches.yml | 30 ++++++++--------- .github/workflows/build-test-recipe.yml | 33 ++++++++++++++----- .github/workflows/ff-merge.yml | 2 +- 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/.github/workflows/build-test-all-branches.yml b/.github/workflows/build-test-all-branches.yml index f0f074729..f11e84ef2 100644 --- a/.github/workflows/build-test-all-branches.yml +++ b/.github/workflows/build-test-all-branches.yml @@ -4,7 +4,7 @@ on: workflow_dispatch: schedule: - cron: '0 0 * * *' - + jobs: trigger-branch-workflows: runs-on: ubuntu-latest @@ -22,26 +22,26 @@ jobs: declare -A run_urls for branch in "${branches[@]}"; do echo "Attempting to trigger workflow for branch: $branch" - + # Trigger the workflow using the GitHub API directly response=$(curl -sS -X POST \ -H "Authorization: token $GITHUB_TOKEN" \ -H "Accept: application/vnd.github.v3+json" \ "https://api.github.com/repos/${{ github.repository }}/actions/workflows/build-test-recipe.yml/dispatches" \ -d "{\"ref\":\"$branch\"}") - + echo "API Response: $response" - + # Check if the workflow was triggered successfully if [ -z "$response" ]; then echo "Workflow triggered successfully for $branch" - + # Get the run ID and URL of the newly triggered workflow sleep 5 # Wait a bit for the workflow to start run_info=$(gh run list --workflow=build-test-recipe.yml --branch=$branch --limit 1 --json databaseId,url) run_id=$(echo "$run_info" | jq -r '.[0].databaseId') run_url=$(echo "$run_info" | jq -r '.[0].url') - + if [ -n "$run_id" ]; then run_ids["$branch"]="$run_id" run_urls["$branch"]="$run_url" @@ -54,7 +54,7 @@ jobs: echo "API Response: $response" fi done - + # Save run IDs and URLs to files for the next steps echo "$(declare -p run_ids)" > run_ids.txt echo "$(declare -p run_urls)" > run_urls.txt @@ -68,16 +68,16 @@ jobs: echo "" >> report.md echo "| Branch | Run ID | Workflow Run |" >> report.md echo "|--------|--------|--------------|" >> report.md - + for branch in "${!run_ids[@]}"; do id="${run_ids[$branch]}" url="${run_urls[$branch]}" echo "| $branch | $id | [View Run]($url) |" >> report.md done - + echo "## Triggered Workflows" >> $GITHUB_STEP_SUMMARY cat report.md >> $GITHUB_STEP_SUMMARY - + echo "Triggered workflows:" cat report.md @@ -86,8 +86,8 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | IFS=' ' read -ra run_ids <<< "${{ env.run_ids }}" - max_attempts=120 # Maximum 120 min exec time - + max_attempts=180 # Maximum 180 min exec time + for attempt in $(seq 1 $max_attempts); do all_completed=true for run_id in "${run_ids[@]}"; do @@ -97,17 +97,17 @@ jobs: break fi done - + if $all_completed; then echo "All branch workflows have completed." break fi - + if [ $attempt -eq $max_attempts ]; then echo "Timeout waiting for workflows to complete." exit 1 fi - + echo "Waiting for workflows to complete... (Attempt $attempt/$max_attempts)" sleep 60 done diff --git a/.github/workflows/build-test-recipe.yml b/.github/workflows/build-test-recipe.yml index 47875a5a4..486711906 100644 --- a/.github/workflows/build-test-recipe.yml +++ b/.github/workflows/build-test-recipe.yml @@ -15,17 +15,34 @@ jobs: - name: Diff files and set variables id: diff run: | - # See https://github.community/t/check-pushed-file-changes-with-git-diff-tree-in-github-actions/17220/10 if [ $GITHUB_BASE_REF ]; then # Pull Request - # 'github.event.before/after' and 'github.event.pull_request.base.sha' are inconsistent for PRs - # Find the commit where the PR branch was forked from the base branch - git fetch origin ${{ github.base_ref }} ${{ github.event.pull_request.head.ref }} - FORK_POINT=$( git show-branch --merge-base "origin/${{ github.base_ref }}" "origin/${{ github.event.pull_request.head.ref }}" ) + # Fetch the base ref + git fetch origin ${{ github.base_ref }}:${{ github.base_ref }} + + # For forks, we need to fetch from the head repository + if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then + git remote add fork ${{ github.event.pull_request.head.repo.clone_url }} + git fetch fork ${{ github.head_ref }} + else + git fetch origin ${{ github.head_ref }}:${{ github.head_ref }} + fi + + # Determine the merge base + FORK_POINT=$(git merge-base ${{ github.base_ref }} ${{ github.event.pull_request.head.sha }}) LATEST_COMMIT_IN_PR=${{ github.event.pull_request.head.sha }} - export DIFF=$( git diff --name-only $FORK_POINT $LATEST_COMMIT_IN_PR ) + + # Get the diff + DIFF=$(git diff --name-only $FORK_POINT $LATEST_COMMIT_IN_PR) echo "Diff between $FORK_POINT and $LATEST_COMMIT_IN_PR" + else + # Push to a branch + BEFORE_SHA=${{ github.event.before }} + AFTER_SHA=${{ github.event.after }} + DIFF=$(git diff --name-only $BEFORE_SHA $AFTER_SHA) + echo "Diff between $BEFORE_SHA and $AFTER_SHA" fi + echo "$DIFF" echo "diff=$( echo "$DIFF" | tr '\n' ' ' )" >> $GITHUB_OUTPUT - name: Get Yocto release name @@ -48,7 +65,7 @@ jobs: - qemuarm - qemuarm64 - qemux86-64 - runs-on: codebuild-${{ vars.CODEBUILD_RUNNER_NAME }}-${{ github.run_id }}-${{ github.run_attempt }} + runs-on: codebuild-${{ vars.CODEBUILD_RUNNER_NAME || 'meta-aws' }}-${{ github.run_id }}-${{ github.run_attempt }} steps: - name: Checkout meta-aws uses: actions/checkout@v4 @@ -72,7 +89,7 @@ jobs: export RECIPES=$( echo "${{ needs.changed.outputs.diff }}" | tr ' ' '\n' | grep '\.bb.*$' | sed 's!.*/!!' | sed 's!.bb!!' | sed 's!_.*!!' | sort | uniq | sed -z $'s/\\\n/ /g') if [ "" == "$RECIPES" ]; then echo "No changed recipes, adding everything with a ptest to test, build" - THINGS_TO_EXCLUDE="! -name aws-lc* ! -name neo-ai-tv* ! -name corretto-17-bin* ! -name corretto-21-bin* ! -name corretto-8-bin* ! -name firecracker-bin* ! -name jailer-bin* ! -name amazon-kvs-producer-sdk-c* ! -name aws-cli-v2* " + THINGS_TO_EXCLUDE="! -name aws-lc* ! -name neo-ai-tv* ! -name corretto-17-bin* ! -name corretto-21-bin* ! -name corretto-8-bin* ! -name firecracker-bin* ! -name jailer-bin* ! -name amazon-kvs-producer-sdk-c* ! -name aws-cli-v2* ! -name aws-iot-device-sdk-cpp-v2-samples-fleet-provisoning* " if [ ${{ matrix.machine }} == "qemuarm" ]; then THINGS_TO_EXCLUDE+="! -name amazon-kvs-webrtc-sdk* ! -name amazon-kvs-producer-pic*" fi diff --git a/.github/workflows/ff-merge.yml b/.github/workflows/ff-merge.yml index 0506e5457..d00f30802 100644 --- a/.github/workflows/ff-merge.yml +++ b/.github/workflows/ff-merge.yml @@ -15,7 +15,7 @@ jobs: fail-fast: false steps: - name: clone meta-aws ${{ github.event.inputs.branches }} branch - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ matrix.branch }} path: meta-aws