ci(pr_test_build_images): Build changed products on PR #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| name: Test Build Images | |
| on: | |
| workflow_dispatch: | |
| pull_request: | |
| branches: [main, 'release/*'] | |
| # For now, we run on all paths, but if the products could be moved into a subdirectory, we could match on that | |
| # paths: [] | |
| env: | |
| GIT_BASE_REF: ${{ github.event.pull_request.base.sha }} | |
| GIT_HEAD_REF: ${{ github.event.pull_request.head.sha }} | |
| jobs: | |
| # The set of paths for changed files (eg: airflow/Dockerfile, zookeeper/stackable/jmx/server.yaml) | |
| # ... limited to the product-paths (eg: airflow, zookeeper) that have a versions.py | |
| # Then for each _product_, shard based on product versions that have the "test" indicator | |
| generate_matrix: | |
| name: Generate Products and Versions Matrix | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
| with: | |
| fetch-depth: 0 | |
| - id: shard | |
| shell: bash | |
| env: | |
| GITHUB_DEBUG: ${{ runner.debug }} | |
| run: | | |
| set -euo pipefail | |
| [ -n "$GITHUB_DEBUG" ] && set -x | |
| # Needed for tomlq | |
| pip install yq==3.4.3 | |
| PRODUCT_VERSION_PAIRS=$( | |
| # shellcheck disable=SC2016 | |
| git diff --name-only "${GIT_BASE_REF}..${GIT_HEAD_REF}" \ | |
| | cut --delimiter=/ --fields=1 | xargs -I {} find {} -type f -maxdepth 1 -name versions.toml \ | |
| | xargs -r dirname \ | |
| | xargs -I {} tomlq --raw-output --arg product "{}" '{"name": $product, "version": .versions | map_values(select(.build_on_pr)) | keys[]}' {}/versions.toml \ | |
| | jq --slurp --compact-output '.' | |
| ) | |
| echo "product_version_pairs=$PRODUCT_VERSION_PAIRS" | tee -a "$GITHUB_OUTPUT" | |
| outputs: | |
| product_version_pairs: ${{ steps.shard.outputs.product_version_pairs }} | |
| build: | |
| name: Build/Publish ${{ matrix.product_version_pairs.name }}-${{ matrix.product_version_pairs.version }}-${{ matrix.runner.arch }} Image | |
| needs: [generate_matrix] | |
| permissions: | |
| id-token: write | |
| runs-on: ${{ matrix.runner.name }} | |
| strategy: | |
| matrix: | |
| runner: | |
| - {name: "ubuntu-latest", arch: "amd64"} | |
| - {name: "ubicloud-standard-8-arm", arch: "arm64"} | |
| # Eg: [{"name":"airflow","version":"2.10.2"},{"name":"airflow","version":"2.9.3"},{"name":"zookeeper","version":"3.9.2"}] | |
| product_version_pairs: ${{ fromJson(needs.generate_matrix.outputs.product_version_pairs) }} | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
| - env: | |
| PRODUCT_NAME: ${{ matrix.product_version_pairs.name }} | |
| PRODUCT_VERSION: ${{ matrix.product_version_pairs.version }} | |
| run: | | |
| echo "PRODUCT_NAME=$PRODUCT_NAME" | |
| echo "PRODUCT_VERSION=$PRODUCT_VERSION" |