|
| 1 | +name: Get CUDAQ build |
| 2 | +description: 'Either restore CUDAQ from cache or build it' |
| 3 | + |
| 4 | +inputs: |
| 5 | + repo: |
| 6 | + description: 'CUDAQ repository.' |
| 7 | + required: true |
| 8 | + ref: |
| 9 | + description: 'The branch, tag or SHA to checkout.' |
| 10 | + required: true |
| 11 | + token: |
| 12 | + description: 'CUDAQ repository access token.' |
| 13 | + default: '' |
| 14 | + required: false |
| 15 | + pr-number: |
| 16 | + description: 'Unique pull request identifier.' |
| 17 | + default: '' |
| 18 | + required: false |
| 19 | + save-build: |
| 20 | + description: 'Indicates whether to save the build' |
| 21 | + default: 'false' |
| 22 | + required: false |
| 23 | + save-ccache: |
| 24 | + description: 'Indicates whether to save the compilation cache' |
| 25 | + default: 'false' |
| 26 | + required: false |
| 27 | + lookup-only: |
| 28 | + description: 'Check if a cache entry exists without downloading the cache' |
| 29 | + default: 'false' |
| 30 | + required: false |
| 31 | +outputs: |
| 32 | + found-cache: |
| 33 | + description: 'A boolean value to indicate that a cache entry was found.' |
| 34 | + value: ${{ steps.check-cache.outputs.valid }} |
| 35 | + |
| 36 | +runs: |
| 37 | + using: "composite" |
| 38 | + steps: |
| 39 | + # ========================================================================== |
| 40 | + # Try to restore from cache |
| 41 | + # ========================================================================== |
| 42 | + |
| 43 | + - name: Create CUDAQ build cache key |
| 44 | + id: cudaq-build-key |
| 45 | + env: |
| 46 | + # This are a list of files that when changed should require a new cudaq build |
| 47 | + to_hash: | |
| 48 | + .github/actions/get-cudaq-build/** |
| 49 | + .cudaq_version |
| 50 | + run: | |
| 51 | + hash=${{ hashFiles(format('{0}', env.to_hash)) }} |
| 52 | + echo "main=cudaq-${{ inputs.ref }}-$hash" >> $GITHUB_OUTPUT |
| 53 | + if [[ -n "${{ inputs.pr-number }}" ]]; then |
| 54 | + echo "pr=-pr${{ inputs.pr-number }}" >> $GITHUB_OUTPUT |
| 55 | + fi |
| 56 | + shell: bash --noprofile --norc -euo pipefail {0} |
| 57 | + |
| 58 | + - name: Try to restoring CUDAQ from cache |
| 59 | + id: restore-cudaq-build |
| 60 | + uses: actions/cache/restore@v4 |
| 61 | + with: |
| 62 | + fail-on-cache-miss: false |
| 63 | + path: /cudaq-install |
| 64 | + key: ${{ steps.cudaq-build-key.outputs.main }}${{ steps.cudaq-build-key.outputs.pr }} |
| 65 | + restore-keys: ${{ steps.cudaq-build-key.outputs.main }} |
| 66 | + lookup-only: ${{ inputs.lookup-only }} |
| 67 | + |
| 68 | + # The restore action could find a partial match using the `restore-keys`. In such cases |
| 69 | + # it would still report `cache-hit` as false, but would load the cache from the partial |
| 70 | + # one. Thus, we need to check whether the cache is valid by other means. |
| 71 | + - name: Check if cache is valid |
| 72 | + id: check-cache |
| 73 | + run: | |
| 74 | + if [[ "${{ steps.restore-cudaq-build.outputs.cache-matched-key }}" == "" ]]; then |
| 75 | + echo "valid=false" >> $GITHUB_OUTPUT |
| 76 | + else |
| 77 | + echo "valid=true" >> $GITHUB_OUTPUT |
| 78 | + fi |
| 79 | + shell: bash --noprofile --norc -euo pipefail {0} |
| 80 | + |
| 81 | + # ========================================================================== |
| 82 | + # Get cuQuantum |
| 83 | + # ========================================================================== |
| 84 | + |
| 85 | + - name: Download assets |
| 86 | + if: steps.check-cache.outputs.valid == 'false' && inputs.lookup-only == 'false' |
| 87 | + env: |
| 88 | + GITHUB_TOKEN: ${{ inputs.token }} |
| 89 | + CUQUANTUM_INSTALL_PREFIX: /cudaq-install |
| 90 | + run: | |
| 91 | + bash .github/workflows/scripts/install_git_cli.sh |
| 92 | + mkdir -p ${CUQUANTUM_INSTALL_PREFIX} |
| 93 | + python3 .github/actions/get-cudaq-build/get_assets.py |
| 94 | + cuquantum_archive=$(jq -r '.cuquantum.pattern' .cudaq_version) |
| 95 | + tar xf "${cuquantum_archive}" --strip-components 1 -C "${CUQUANTUM_INSTALL_PREFIX}" |
| 96 | + shell: bash --noprofile --norc -euo pipefail {0} |
| 97 | + |
| 98 | + # ========================================================================== |
| 99 | + # Build CUDAQ |
| 100 | + # ========================================================================== |
| 101 | + |
| 102 | + - name: Get CUDAQ code |
| 103 | + if: steps.check-cache.outputs.valid == 'false' && inputs.lookup-only == 'false' |
| 104 | + uses: actions/checkout@v4 |
| 105 | + with: |
| 106 | + repository: ${{ inputs.repo }} |
| 107 | + ref: ${{ inputs.ref }} |
| 108 | + path: cudaq |
| 109 | + set-safe-directory: true |
| 110 | + |
| 111 | + - name: Try to restoring CUDAQ compilation cache |
| 112 | + if: steps.check-cache.outputs.valid == 'false' && inputs.lookup-only == 'false' |
| 113 | + id: restore-ccache |
| 114 | + uses: actions/cache/restore@v4 |
| 115 | + with: |
| 116 | + fail-on-cache-miss: false |
| 117 | + path: /cudaq-ccache |
| 118 | + key: ccache-cudaq |
| 119 | + |
| 120 | + - name: Install CUDAQ build requirements |
| 121 | + if: steps.check-cache.outputs.valid == 'false' && inputs.lookup-only == 'false' |
| 122 | + run: | |
| 123 | + bash .github/workflows/scripts/install_git_cli.sh |
| 124 | + apt install -y --no-install-recommends ccache |
| 125 | + shell: bash --noprofile --norc -euo pipefail {0} |
| 126 | + |
| 127 | + - name: Build CUDAQ |
| 128 | + if: steps.check-cache.outputs.valid == 'false' && inputs.lookup-only == 'false' |
| 129 | + env: |
| 130 | + CCACHE_DIR: /cudaq-ccache |
| 131 | + cudaq-build-script: .github/actions/get-cudaq-build/build_cudaq.sh |
| 132 | + CUQUANTUM_INSTALL_PREFIX: /cudaq-install |
| 133 | + CUTENSOR_INSTALL_PREFIX: /cudaq-install |
| 134 | + CUDAQ_INSTALL_PREFIX: /cudaq-install |
| 135 | + run: bash ${{ env.cudaq-build-script }} Release ccache gcc-11 g++-11 |
| 136 | + shell: bash --noprofile --norc -euo pipefail {0} |
| 137 | + |
| 138 | + # ========================================================================== |
| 139 | + # Store CUDAQ compilation cache |
| 140 | + # ========================================================================== |
| 141 | + |
| 142 | + # We need to delete previous cache entry otherwise the new one won't be stored |
| 143 | + - name: Delete previous compilation cache |
| 144 | + if: steps.restore-ccache.outputs.cache-hit == 'true' && inputs.save-ccache == 'true' |
| 145 | + env: |
| 146 | + GH_TOKEN: ${{ github.token }} |
| 147 | + run: | |
| 148 | + gh cache delete ccache-cudaq --repo ${{ github.repository }} |
| 149 | + shell: bash --noprofile --norc -euo pipefail {0} |
| 150 | + |
| 151 | + - name: Store compilation (CCache) |
| 152 | + if: steps.check-cache.outputs.valid == 'false' && inputs.save-ccache == 'true' && inputs.lookup-only == 'false' |
| 153 | + uses: actions/cache/save@v4 |
| 154 | + with: |
| 155 | + path: /cudaq-ccache |
| 156 | + key: ccache-cudaq |
| 157 | + |
| 158 | + |
| 159 | + # ========================================================================== |
| 160 | + # Store CUDAQ build cache |
| 161 | + # ========================================================================== |
| 162 | + |
| 163 | + - name: Store CUDAQ build in the cache |
| 164 | + if: steps.check-cache.outputs.valid == 'false' && inputs.save-build == 'true' && inputs.lookup-only == 'false' |
| 165 | + uses: actions/cache/save@v4 |
| 166 | + with: |
| 167 | + path: /cudaq-install |
| 168 | + key: ${{ steps.cudaq-build-key.outputs.main }}${{ steps.cudaq-build-key.outputs.pr }} |
0 commit comments