From 37e493ce0d180f994109651bab55f8b5fdb1b215 Mon Sep 17 00:00:00 2001 From: DevTekVE Date: Mon, 23 Dec 2024 00:37:02 +0100 Subject: [PATCH] CI: Add GitHub Action to build models from upstream (#491) * Add support for custom model naming in workflow This update introduces a new optional input `custom_name` to the `sunnypilot-build-model` GitHub workflow. If provided, it customizes the artifact name; otherwise, the default naming scheme is used. This enhances flexibility for build artifact identification. * fix name * Update cache key logic in build workflow Replaced `github.ref_name` with a fallback to `github.head_ref || github.ref_name` in cache keys to handle branches and pull requests more reliably. This ensures consistent cache retrieval and improves workflow efficiency. * Simplify artifact upload logic in CI workflow Consolidated redundant artifact upload steps into a single action, leveraging a fallback mechanism for naming. This streamlines the workflow, reducing duplication and improving maintainability. * Make publish step resilient and add conditional notify Added `continue-on-error` to the publish step to allow workflow progression even if it fails. Introduced a condition to notify step that depends on publish outcome being successful. These changes improve workflow reliability and error handling. * Fix conditional syntax in GitHub Actions workflow Updated the conditional statement in the notify job to use the correct GitHub Actions expression syntax. This ensures proper evaluation of the publish step's success outcome. * Update condition for notify step in GitHub Actions workflow Replaced the deprecated syntax `${{ steps.publish.outcome == 'success' }}` with the recommended `success()` function. This ensures compatibility with newer GitHub Actions features and improves maintainability. * Update build workflow to handle PR drafts and improve concurrency Added support for pull request draft events to trigger the workflow, ensuring drafts are not missed. Removed `continue-on-error` in the publish step to improve reliability and prevent silent failures. Simplifies and enhances workflow robustness. * Update pull request workflows and add draft check logic Removed unnecessary pull request event types and drafts settings, consolidating logic. Added a condition to skip publishing for non-draft pull requests, ensuring better control over the deployment process. --- .github/workflows/sunnypilot-build-model.yaml | 16 ++++++++++------ .github/workflows/sunnypilot-build-prebuilt.yaml | 2 ++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/sunnypilot-build-model.yaml b/.github/workflows/sunnypilot-build-model.yaml index bc4bd4f4a..b01a7a062 100644 --- a/.github/workflows/sunnypilot-build-model.yaml +++ b/.github/workflows/sunnypilot-build-model.yaml @@ -14,6 +14,10 @@ on: required: true default: 'master' type: string + custom_name: + description: 'Custom name for the model' + required: false + type: string jobs: build_model: @@ -32,11 +36,11 @@ jobs: uses: actions/cache@v4 with: path: ${{env.SCONS_CACHE_DIR}} - key: scons-${{ runner.os }}-${{ runner.arch }}-${{ github.ref_name }}-model-${{ github.head_ref }}-${{ github.sha }} + key: scons-${{ runner.os }}-${{ runner.arch }}-${{ github.head_ref || github.ref_name }}-model-${{ github.sha }} restore-keys: | - scons-${{ runner.os }}-${{ runner.arch }}-${{ github.ref_name }}-model-${{ github.head_ref }} - scons-${{ runner.os }}-${{ runner.arch }}-${{ github.ref_name }}-model - scons-${{ runner.os }}-${{ runner.arch }}-${{ github.ref_name }} + scons-${{ runner.os }}-${{ runner.arch }}-${{ github.head_ref || github.ref_name }}-model-${{ github.sha }} + scons-${{ runner.os }}-${{ runner.arch }}-${{ github.head_ref || github.ref_name }}-model + scons-${{ runner.os }}-${{ runner.arch }}-${{ github.head_ref || github.ref_name }} scons-${{ runner.os }}-${{ runner.arch }}-master-new scons-${{ runner.os }}-${{ runner.arch }}-master scons-${{ runner.os }}-${{ runner.arch }} @@ -78,5 +82,5 @@ jobs: - name: Upload Build Artifacts uses: actions/upload-artifact@v4 with: - name: model-${{ github.event.inputs.upstream_branch }}-${{ github.run_number }} - path: ${{ env.OUTPUT_DIR }} \ No newline at end of file + name: model-${{ github.event.inputs.custom_name || github.event.inputs.upstream_branch }}-${{ github.run_number }} + path: ${{ env.OUTPUT_DIR }} diff --git a/.github/workflows/sunnypilot-build-prebuilt.yaml b/.github/workflows/sunnypilot-build-prebuilt.yaml index 04556e3a4..367f292e0 100644 --- a/.github/workflows/sunnypilot-build-prebuilt.yaml +++ b/.github/workflows/sunnypilot-build-prebuilt.yaml @@ -191,6 +191,7 @@ jobs: concurrency: group: publish-${{ github.head_ref || github.ref_name }} cancel-in-progress: true + if: ${{ github.event_name != 'pull_request' || github.event_name == 'pull_request' && github.event.pull_request.draft }} needs: build runs-on: ubuntu-24.04 environment: ${{ contains(fromJSON(vars.AUTO_DEPLOY_PREBUILT_BRANCHES), github.head_ref || github.ref_name) && 'auto-deploy' || 'feature-branch' }} @@ -237,6 +238,7 @@ jobs: notify: needs: [ build, publish ] runs-on: ubuntu-24.04 + if: success() steps: - uses: actions/checkout@v4 - name: Setup Alpine Linux environment