|
| 1 | +# |
| 2 | +# This workflow was created automatically from the `package-template.yml` by running `make -C .github workflows` |
| 3 | +# DO NOT EDIT THIS WORKFLOW, changes will be lost on the next update. |
| 4 | +# |
| 5 | + |
| 6 | +name: "cilium-cli" |
| 7 | +concurrency: |
| 8 | + group: ${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }} (${{ inputs.package_version_override || 'LATEST' }}_r${{ inputs.release_number_override || '0' }}) |
| 9 | + cancel-in-progress: true |
| 10 | +on: |
| 11 | + push: |
| 12 | + branches: |
| 13 | + - main |
| 14 | + |
| 15 | + paths: |
| 16 | + - apk/** |
| 17 | + - deb/** |
| 18 | + - rpm/** |
| 19 | + - tasks/** |
| 20 | + - vendor/cilium-cli/** |
| 21 | + - .github/workflows/cilium-cli.yml |
| 22 | + |
| 23 | + |
| 24 | + pull_request: |
| 25 | + types: [opened, synchronize, reopened] |
| 26 | + paths: |
| 27 | + - apk/** |
| 28 | + - deb/** |
| 29 | + - rpm/** |
| 30 | + - tasks/** |
| 31 | + - vendor/cilium-cli/** |
| 32 | + - .github/workflows/cilium-cli.yml |
| 33 | + |
| 34 | + #bridgecrew:skip=BC_REPO_GITHUB_ACTION_7:The whole point of the workflow dispatch is to feed in a version |
| 35 | + workflow_dispatch: |
| 36 | + inputs: |
| 37 | + package_version_override: |
| 38 | + description: 'Version of cilium-cli package to build. Defaults to vendor/cilium-cli/VERSION.' |
| 39 | + required: false |
| 40 | + type: string |
| 41 | + release_number_override: |
| 42 | + description: 'Zero-based release number of cilium-cli package to publish. Defaults to 0 (zero) when version is specified, ignored if not.' |
| 43 | + required: false |
| 44 | + type: string |
| 45 | + |
| 46 | +env: |
| 47 | + cilium-cli_VERSION: ${{ inputs.package_version_override }} |
| 48 | + cilium-cli_RELEASE: ${{ inputs.release_number_override }} |
| 49 | + |
| 50 | +jobs: |
| 51 | + # Mergify cannot distinguish between 2 jobs with the same name run from different workflows, |
| 52 | + # so each job must have a unique name for the rules to work properly. |
| 53 | + # See https://github.com/Mergifyio/mergify/discussions/5082 |
| 54 | + # and https://github.com/Mergifyio/mergify/issues/5083 |
| 55 | + matrix-cilium-cli: |
| 56 | + if: github.event_name != 'schedule' |
| 57 | + runs-on: ubuntu-latest |
| 58 | + outputs: |
| 59 | + package-enabled: ${{ steps.info.outputs.package_enabled }} |
| 60 | + package-matrix: ${{steps.info.outputs.package_matrix}} |
| 61 | + arch-matrix: ${{steps.info.outputs.arch_matrix}} |
| 62 | + apk-enabled: ${{ steps.info.outputs.package_enabled == 'true' && steps.info.outputs.apk_package_enabled == 'true' }} |
| 63 | + steps: |
| 64 | + - uses: actions/checkout@v4 |
| 65 | + |
| 66 | + - name: Export package build matrix |
| 67 | + shell: bash |
| 68 | + id: info |
| 69 | + env: |
| 70 | + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" |
| 71 | + run: | |
| 72 | + echo setting ouputs |
| 73 | + make -C vendor/cilium-cli info/github |
| 74 | + echo |
| 75 | + echo outputs set |
| 76 | +
|
| 77 | +
|
| 78 | + # Build for alpine linux |
| 79 | + # Kept separate because it is old and slightly different than the other package builds |
| 80 | + alpine-cilium-cli: |
| 81 | + needs: matrix-cilium-cli |
| 82 | + if: github.event_name != 'schedule' && needs.matrix-cilium-cli.outputs.apk-enabled != 'false' |
| 83 | + runs-on: ubuntu-latest |
| 84 | + strategy: |
| 85 | + matrix: |
| 86 | + # These versions must be strings. E.g. Otherwise `3.10` -> `3.1` |
| 87 | + alpine: |
| 88 | + # Now that we are just building 1 binary for all distributions, we do not |
| 89 | + # need to track which distribution we are building on. |
| 90 | + - 'alpine' |
| 91 | + env: |
| 92 | + APK_KEY_RSA: "${{ secrets.APK_KEY_RSA }}" |
| 93 | + APK_PACKAGES_PATH: ${{github.workspace}}/artifacts/${{matrix.alpine}} |
| 94 | + PACKAGER: ops@cloudposse.com |
| 95 | + PACKAGER_PRIVKEY: /dev/shm/ops@cloudposse.com.rsa |
| 96 | + PACKAGER_PUBKEY: ${{github.workspace}}/artifacts/ops@cloudposse.com.rsa.pub |
| 97 | + |
| 98 | + container: |
| 99 | + image: cloudposse/packages-apkbuild:${{matrix.alpine}} |
| 100 | + credentials: |
| 101 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 102 | + password: ${{ secrets.DOCKERHUB_PASSWORD }} |
| 103 | + |
| 104 | + steps: |
| 105 | + # Checkout the packages repo so we can build the packages as a monorepo |
| 106 | + - name: "Checkout source code at current commit" |
| 107 | + uses: actions/checkout@v4 |
| 108 | + |
| 109 | + # Export the apk keys as files from secrets |
| 110 | + - name: "Export keys" |
| 111 | + run: "make -C .github/ export" |
| 112 | + |
| 113 | + # Build the alpine packages for the matrix version of alpine |
| 114 | + - name: "Build alpine packages" |
| 115 | + run: "make -C vendor/${{github.workflow}} apk" |
| 116 | + |
| 117 | + # Verify the packages were built or error |
| 118 | + - name: "List packages" |
| 119 | + run: 'find ${APK_PACKAGES_PATH} -type f -name \*.apk | xargs --no-run-if-empty ls -l | grep .' |
| 120 | + |
| 121 | + # Export the artifact filename including path |
| 122 | + # Path must be relative to workdir for Cloudsmith action to be able to find it |
| 123 | + - name: "Set output path to artifact" |
| 124 | + id: artifact |
| 125 | + shell: bash |
| 126 | + run: | |
| 127 | + artifact=$(find artifacts/${{matrix.alpine}} -type f -name \*.apk) |
| 128 | + echo "path=$artifact" | tee -a $GITHUB_OUTPUT |
| 129 | + echo creating '"pip"' cache directory for Cloudsmith |
| 130 | + mkdir -p $HOME/.cache/pip && chmod -R 777 $HOME/.cache || echo Ignoring error creating '"pip"' cache directory |
| 131 | +
|
| 132 | +
|
| 133 | + # Determine which package organization we should use (e.g. dev or prod) |
| 134 | + - name: "Determine package repo" |
| 135 | + shell: bash |
| 136 | + id: repo |
| 137 | + run: | |
| 138 | + if [[ ${GITHUB_REF} == 'refs/heads/main' ]]; then |
| 139 | + echo "org=${{github.repository_owner}}" | tee -a $GITHUB_OUTPUT |
| 140 | + else |
| 141 | + echo "org=${{github.repository_owner}}-dev" | tee -a $GITHUB_OUTPUT |
| 142 | + fi |
| 143 | + env: |
| 144 | + GITHUB_REF: ${{ github.ref }} |
| 145 | + |
| 146 | + # Publish the artifacts |
| 147 | + - name: "Push artifact to package repository" |
| 148 | + uses: cloudsmith-io/action@v0.5.4 |
| 149 | + with: |
| 150 | + api-key: ${{ secrets.CLOUDSMITH_API_KEY }} |
| 151 | + command: 'push' |
| 152 | + format: 'alpine' |
| 153 | + owner: '${{steps.repo.outputs.org}}' # Your Cloudsmith account name or org name (namespace) |
| 154 | + repo: 'packages' # Your Cloudsmith Repository name (slug) |
| 155 | + distro: 'alpine' # Your Distribution (i.e debian, ubuntu, alpine) |
| 156 | + release: 'any-version' # Use "any-version" if your package is compatible with more than one version of alpine linux |
| 157 | + republish: 'true' # Needed if version is not changing |
| 158 | + file: '${{steps.artifact.outputs.path}}' # Package filename (including path) |
| 159 | + no-wait-for-sync: 'true' # Skip the waiting for package synchronisation (i.e. upload only) |
| 160 | + |
| 161 | + # Build packages with fpm package manager |
| 162 | + package-cilium-cli: |
| 163 | + needs: matrix-cilium-cli |
| 164 | + # Should not be needed, but without these conditions, this job would fail with an error if the matrix is [] |
| 165 | + # and would run with package-type empty if matrix is ["apk"] |
| 166 | + if: > |
| 167 | + github.event_name != 'schedule' && needs.matrix-cilium-cli.outputs.package-enabled != 'false' |
| 168 | + && needs.matrix-cilium-cli.outputs.package-matrix != '[]' && needs.matrix-cilium-cli.outputs.package-matrix != '["apk"]' |
| 169 | +
|
| 170 | + strategy: |
| 171 | + matrix: |
| 172 | + package-type: ${{ fromJSON(needs.matrix-cilium-cli.outputs.package-matrix) }} |
| 173 | + arch: ${{ fromJSON(needs.matrix-cilium-cli.outputs.arch-matrix) }} |
| 174 | + exclude: |
| 175 | + - package-type: 'apk' |
| 176 | + include: |
| 177 | + # Default value for runs-on. Original matrix values will not be overridden, but added ones (like runs-on) can be. |
| 178 | + # See https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#expanding-or-adding-matrix-configurations |
| 179 | + - runs-on: "self-hosted-arm64-large" |
| 180 | + # By including `arch: amd64` here, we override the `runs-on` value when the matrix `arch` is `amd64`. |
| 181 | + # This also forces the matrix to include `arch: amd64` even if it is not in the original matrix. |
| 182 | + # This is why we do not default for amd64 and then override for arm64. (Because it would force arm64 to be included, and some tools are not available for arm64.) |
| 183 | + - arch: amd64 |
| 184 | + runs-on: "ubuntu-latest" |
| 185 | + runs-on: ${{ matrix.runs-on }} |
| 186 | + env: |
| 187 | + # We are in a bit of a bind here because of how GitHub actions work as of 2020-11-19 |
| 188 | + # Although the "workspace" is mounted to the container, it is not mounted |
| 189 | + # at `/github/workspace` or ${{github.workspace}}, although through some |
| 190 | + # mechanism, an environment variable whose value starts with ${{github.workspace}} |
| 191 | + # will have ${{github.workspace}} replaced with the correct mount point. |
| 192 | + # |
| 193 | + # We need an absolute path for the package build system, since every build happens |
| 194 | + # in a different directory, but because the mount point changes, we also |
| 195 | + # need a path relative to the initial working directory to communicate between |
| 196 | + # the package building container and the cloudsmith action. |
| 197 | + PACKAGES_PATH: ${{github.workspace}}/artifacts/${{matrix.package-type}}/any-version |
| 198 | + PACKAGE_RELPATH: artifacts/${{matrix.package-type}}/any-version |
| 199 | + |
| 200 | + # Unfortunately, there is no reasonable way to configure the docker image tag based on the package-type |
| 201 | + container: |
| 202 | + image: cloudposse/packages-${{matrix.package-type}}build:latest |
| 203 | + credentials: |
| 204 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 205 | + password: ${{ secrets.DOCKERHUB_PASSWORD }} |
| 206 | + |
| 207 | + steps: |
| 208 | + # Checkout the packages repo so we can build the packages as a monorepo |
| 209 | + - name: "Checkout source code at current commit" |
| 210 | + uses: actions/checkout@v4 |
| 211 | + |
| 212 | + # Build the packages for the matrix version |
| 213 | + - name: "Build ${{matrix.package-type}} packages" |
| 214 | + shell: bash |
| 215 | + run: | |
| 216 | + echo Current directory is $(pwd) |
| 217 | + [[ $PACKAGES_PATH =~ ^$(pwd) ]] || { echo Package dir \"$PACKAGES_PATH\" not beneath workdir \"$(pwd)\" >&2; exit 1; } |
| 218 | + make -C vendor/${{github.workflow}} ${{matrix.package-type}} |
| 219 | +
|
| 220 | + # Export the artifact filename including path |
| 221 | + - name: "Set output path to artifact" |
| 222 | + id: artifact |
| 223 | + shell: bash |
| 224 | + run: | |
| 225 | + [[ -n $PACKAGE_RELPATH ]] || { echo Error: PACKAGE_RELPATH is not set >&2; exit 1; } |
| 226 | + packages=($(find ${PACKAGE_RELPATH} -type f -name \*.${{matrix.package-type}})) |
| 227 | + echo List packages found: |
| 228 | + printf "%s\n" "${packages[@]}" | xargs --no-run-if-empty ls -l |
| 229 | + echo Error if not exactly 1 package found |
| 230 | + (( ${#packages[@]} == 1 )) || { echo "Error: other than 1 package found (${#packages[@]})" >&2; exit 1; } |
| 231 | +
|
| 232 | + echo "setting output" |
| 233 | + echo "path=$packages" | tee -a $GITHUB_OUTPUT |
| 234 | +
|
| 235 | + echo creating '"pip"' cache directory for Cloudsmith |
| 236 | + mkdir -p $HOME/.cache/pip && chmod -R 777 $HOME/.cache || echo Ignoring error creating '"pip"' cache directory |
| 237 | +
|
| 238 | + # Determine which package organization we should use (e.g. dev or prod) |
| 239 | + - name: "Determine package repo" |
| 240 | + shell: bash |
| 241 | + id: repo |
| 242 | + run: | |
| 243 | + if [[ ${GITHUB_REF} == 'refs/heads/main' ]]; then |
| 244 | + echo "org=${{github.repository_owner}}" | tee -a $GITHUB_OUTPUT |
| 245 | + else |
| 246 | + echo "org=${{github.repository_owner}}-dev" | tee -a $GITHUB_OUTPUT |
| 247 | + fi |
| 248 | + env: |
| 249 | + GITHUB_REF: ${{ github.ref }} |
| 250 | + |
| 251 | + # Publish the artifacts |
| 252 | + - name: "Push artifact to package repository" |
| 253 | + uses: cloudsmith-io/action@v0.5.4 |
| 254 | + with: |
| 255 | + api-key: ${{ secrets.CLOUDSMITH_API_KEY }} |
| 256 | + command: 'push' |
| 257 | + format: '${{matrix.package-type}}' |
| 258 | + owner: '${{steps.repo.outputs.org}}' # Your Cloudsmith account name or org name (namespace) |
| 259 | + repo: 'packages' # Your Cloudsmith Repository name (slug) |
| 260 | + distro: 'any-distro' # Use "any-distro" since our package is compatible with more than more distribution |
| 261 | + release: 'any-version' # Use "any-version" since our package is compatible with more than more version |
| 262 | + republish: 'true' # Needed if version is not changing |
| 263 | + file: '${{steps.artifact.outputs.path}}' # Package filename (including path) |
| 264 | + no-wait-for-sync: 'true' # Skip the waiting for package synchronisation (i.e. upload only) |
0 commit comments