# A reusable github actions workflow that will build xtask, if it is not # already cached. # # It will create a pair of GHA cache entries, if they do not already exist. # The cache keys take the form `xtask-{os}-{hash}`, where "{os}" is "linux" # or "macos", and "{hash}" is the hash of the xtask# directory. # # The cache keys are written to output variables named "cachekey-{os}". # name: Build xtask if necessary on: workflow_call: outputs: cachekey-linux: description: "The cache key for the linux build artifact" value: "${{ jobs.xtask.outputs.cachekey-linux }}" cachekey-macos: description: "The cache key for the macos build artifact" value: "${{ jobs.xtask.outputs.cachekey-macos }}" permissions: {} env: CARGO_TERM_COLOR: always jobs: xtask: name: "xtask-${{ matrix.os-name }}" strategy: fail-fast: true matrix: include: - os: ubuntu-latest os-name: 🐧 cachekey-id: linux - os: macos-15 os-name: 🍏 cachekey-id: macos runs-on: "${{ matrix.os }}" steps: - name: Checkout repo uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 with: persist-credentials: false - name: Calculate cache key id: cachekey # set a step output variable "cachekey-{os}" that can be referenced in # the job outputs below. run: | echo "cachekey-${{ matrix.cachekey-id }}=xtask-${{ matrix.cachekey-id }}-${{ hashFiles('Cargo.toml', 'xtask/**') }}" >> $GITHUB_OUTPUT - name: Check xtask cache uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 id: xtask-cache with: path: target/debug/xtask # use the cache key calculated in the step above. Bit of an awkward # syntax key: | ${{ steps.cachekey.outputs[format('cachekey-{0}', matrix.cachekey-id)] }} - name: Install Rust stable toolchain if: steps.xtask-cache.outputs.cache-hit != 'true' uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # v1 with: toolchain: stable - name: Build if: steps.xtask-cache.outputs.cache-hit != 'true' run: | cargo build -p xtask outputs: "cachekey-linux": "${{ steps.cachekey.outputs.cachekey-linux }}" "cachekey-macos": "${{ steps.cachekey.outputs.cachekey-macos }}"