|
| 1 | +version: "1.0" |
| 2 | +mode: parallel |
| 3 | + |
| 4 | +stages: |
| 5 | + - Prepare |
| 6 | + - Test |
| 7 | + - Build |
| 8 | + - Push Dev |
| 9 | + - Release |
| 10 | + |
| 11 | +steps: |
| 12 | + main_clone: |
| 13 | + stage: Prepare |
| 14 | + title: clone repository |
| 15 | + type: git-clone |
| 16 | + git: cf_github |
| 17 | + repo: ${{CF_REPO_OWNER}}/${{CF_REPO_NAME}} |
| 18 | + revision: ${{CF_BRANCH}} |
| 19 | + |
| 20 | + prepare_env_vars: &deps |
| 21 | + stage: Prepare |
| 22 | + title: prepare-env |
| 23 | + image: quay.io/codefresh/golang-ci-helper:latest |
| 24 | + commands: |
| 25 | + - cf_export GO111MODULE=on |
| 26 | + - cf_export GOCACHE=/codefresh/volume/gocache # change gopath to codefresh shared volume |
| 27 | + - cf_export GOPATH=/codefresh/volume/gopath |
| 28 | + - cf_export GOPRIVATE=github.com/codefresh-io/argo-platform |
| 29 | + - cf_export GOSUMDB=off |
| 30 | + - cf_export PATH=$PATH:/codefresh/volume/gopath/bin |
| 31 | + - cf_export LATEST_VERSION=$(curl --silent -H "Authorization:Bearer ${{GITHUB_TOKEN}}" "https://api.github.com/repos/${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}/releases/latest" | jq -r ".tag_name") |
| 32 | + - cf_export VERSION=$(make cur-version) |
| 33 | + when: |
| 34 | + steps: |
| 35 | + - name: main_clone |
| 36 | + on: |
| 37 | + - success |
| 38 | + |
| 39 | + compare_versions: |
| 40 | + stage: Prepare |
| 41 | + title: compare versions |
| 42 | + image: alpine/semver |
| 43 | + commands: |
| 44 | + - semver "${{VERSION}}" -r ">${{LATEST_VERSION}}" || (echo "bump version! current is ${{VERSION}} latest is ${{LATEST_VERSION}}" && exit 1) |
| 45 | + when: |
| 46 | + steps: |
| 47 | + - name: prepare_env_vars |
| 48 | + on: |
| 49 | + - success |
| 50 | + |
| 51 | + download_modules: |
| 52 | + <<: *deps |
| 53 | + stage: Prepare |
| 54 | + title: download modules |
| 55 | + commands: |
| 56 | + - git config --global url."https://github:${GITHUB_TOKEN}@github.com".insteadOf "https://github.com" |
| 57 | + - go mod tidy |
| 58 | + - make clean |
| 59 | + when: |
| 60 | + steps: |
| 61 | + - name: compare_versions |
| 62 | + on: |
| 63 | + - success |
| 64 | + |
| 65 | + lint: |
| 66 | + <<: *deps |
| 67 | + stage: Test |
| 68 | + title: lint |
| 69 | + commands: |
| 70 | + - make lint |
| 71 | + - make check-worktree |
| 72 | + when: |
| 73 | + steps: |
| 74 | + - name: download_modules |
| 75 | + on: |
| 76 | + - success |
| 77 | + |
| 78 | + codegen: |
| 79 | + <<: *deps |
| 80 | + stage: Test |
| 81 | + title: check codegen |
| 82 | + commands: |
| 83 | + - make codegen |
| 84 | + - make check-worktree |
| 85 | + when: |
| 86 | + steps: |
| 87 | + - name: download_modules |
| 88 | + on: |
| 89 | + - success |
| 90 | + |
| 91 | + test: |
| 92 | + <<: *deps |
| 93 | + stage: Test |
| 94 | + title: run tests |
| 95 | + commands: |
| 96 | + - make test |
| 97 | + when: |
| 98 | + steps: |
| 99 | + - name: lint |
| 100 | + on: |
| 101 | + - success |
| 102 | + |
| 103 | + codecov-report: |
| 104 | + stage: Test |
| 105 | + type: codecov-reporter |
| 106 | + title: report code coverage |
| 107 | + arguments: |
| 108 | + codecov_integration: ${{CODECOV_INTEGRATION}} |
| 109 | + when: |
| 110 | + steps: |
| 111 | + - name: test |
| 112 | + on: |
| 113 | + - success |
| 114 | + |
| 115 | + build: |
| 116 | + stage: Build |
| 117 | + title: build docker image |
| 118 | + type: build |
| 119 | + image_name: ${{IMAGE_NAME}} |
| 120 | + tag: ${{CF_BRANCH_TAG_NORMALIZED}} |
| 121 | + buildkit: true |
| 122 | + disable_push: true |
| 123 | + build_arguments: |
| 124 | + - GITHUB_TOKEN=${{GITHUB_TOKEN}} |
| 125 | + - SEGMENT_WRITE_KEY=${{SEGMENT_WRITE_KEY}} |
| 126 | + when: |
| 127 | + condition: |
| 128 | + all: |
| 129 | + isBinary: '"${{REPO_TYPE}}" != "lib"' |
| 130 | + steps: |
| 131 | + - name: compare_versions |
| 132 | + on: |
| 133 | + - success |
| 134 | + |
| 135 | + push_dev: |
| 136 | + stage: Push Dev |
| 137 | + title: push with dev tags |
| 138 | + type: push |
| 139 | + candidate: ${{build}} |
| 140 | + tags: |
| 141 | + - dev-${{CF_BRANCH_TAG_NORMALIZED}} |
| 142 | + when: |
| 143 | + steps: |
| 144 | + - name: build |
| 145 | + on: |
| 146 | + - success |
| 147 | + branch: |
| 148 | + ignore: ["main"] |
| 149 | + scale: |
| 150 | + push_quay_dev: |
| 151 | + title: push to quay |
| 152 | + registry: "${{REGISTRY_INTEGRATION_QUAY}}" |
| 153 | + |
| 154 | + build_binaries: |
| 155 | + <<: *deps |
| 156 | + stage: Build |
| 157 | + title: build binaries |
| 158 | + commands: |
| 159 | + - make ./dist/cf-${TARGET}.sha256 DEV_MODE=false SEGMENT_WRITE_KEY=${{SEGMENT_WRITE_KEY}} |
| 160 | + scale: |
| 161 | + linux_amd64: |
| 162 | + title: linux_amd64 |
| 163 | + environment: |
| 164 | + - TARGET=linux-amd64 |
| 165 | + linux_arm64: |
| 166 | + title: linux_arm64 |
| 167 | + environment: |
| 168 | + - TARGET=linux-arm64 |
| 169 | + windows_amd64: |
| 170 | + title: windows_amd64 |
| 171 | + environment: |
| 172 | + - TARGET=windows-amd64 |
| 173 | + darwin_amd64: |
| 174 | + title: darwin_amd64 |
| 175 | + environment: |
| 176 | + - TARGET=darwin-amd64 |
| 177 | + darwin_arm64: |
| 178 | + title: darwin_arm64 |
| 179 | + environment: |
| 180 | + - TARGET=darwin-arm64 |
| 181 | + retry: |
| 182 | + maxAttempts: 3 |
| 183 | + delay: 1 |
| 184 | + when: |
| 185 | + condition: |
| 186 | + all: |
| 187 | + isBinary: '"${{REPO_TYPE}}" != "lib"' |
| 188 | + branch: |
| 189 | + only: ["main"] |
| 190 | + steps: |
| 191 | + - name: test |
| 192 | + on: |
| 193 | + - success |
| 194 | + - name: codegen |
| 195 | + on: |
| 196 | + - success |
| 197 | + - name: lint |
| 198 | + on: |
| 199 | + - success |
| 200 | + |
| 201 | + create_release_lib: |
| 202 | + <<: *deps |
| 203 | + stage: Release |
| 204 | + title: create github release - lib |
| 205 | + commands: |
| 206 | + - export GIT_REPO=${{CF_REPO_OWNER}}/${{CF_REPO_NAME}} |
| 207 | + - export GIT_BRANCH=${{CF_BRANCH}} |
| 208 | + - make release |
| 209 | + when: |
| 210 | + condition: |
| 211 | + all: |
| 212 | + isBinary: '"${{REPO_TYPE}}" == "lib"' |
| 213 | + steps: |
| 214 | + - name: test |
| 215 | + on: |
| 216 | + - success |
| 217 | + - name: codegen |
| 218 | + on: |
| 219 | + - success |
| 220 | + |
| 221 | + create_release_bin: |
| 222 | + <<: *deps |
| 223 | + stage: Release |
| 224 | + title: create github release - bin |
| 225 | + commands: |
| 226 | + - export GIT_REPO=${{CF_REPO_OWNER}}/${{CF_REPO_NAME}} |
| 227 | + - export GIT_BRANCH=${{CF_BRANCH}} |
| 228 | + - make release |
| 229 | + when: |
| 230 | + branch: |
| 231 | + only: ["main"] |
| 232 | + steps: |
| 233 | + - name: build_binaries |
| 234 | + on: |
| 235 | + - success |
| 236 | + - name: build |
| 237 | + on: |
| 238 | + - success |
| 239 | + |
| 240 | + bump_brew_formula: |
| 241 | + stage: Release |
| 242 | + title: bump brew formula version |
| 243 | + image: codefresh/build-cli |
| 244 | + commands: |
| 245 | + - echo "generate formula from template ..." |
| 246 | + - sed -e "s/{{ version }}/${{VERSION}}/g" -e "s/{{ revision }}/${{CF_REVISION}}/g" ./brew/template.rb > ${{BREW_NAME}}.rb |
| 247 | + - echo "Updating file in GitHub" |
| 248 | + - FORMULA_SHA256=$(curl -X GET https://api.github.com/repos/codefresh-io/homebrew-cli/contents/Formula/${{BREW_NAME}}.rb | jq .sha) |
| 249 | + - | |
| 250 | + curl -v -i -X PUT -H 'Authorization: token '$GITHUB_TOKEN'' -d "{ \ |
| 251 | + \"message\": \"update formula version $VERSION\", \ |
| 252 | + \"content\": \"$(openssl base64 -A -in ${{BREW_NAME}}.rb)\", \ |
| 253 | + \"sha\": $FORMULA_SHA256 \ |
| 254 | + }" https://api.github.com/repos/codefresh-io/homebrew-cli/contents/Formula/${{BREW_NAME}}.rb |
| 255 | + when: |
| 256 | + steps: |
| 257 | + - name: create_release_bin |
| 258 | + on: |
| 259 | + - success |
| 260 | + condition: |
| 261 | + all: |
| 262 | + whenVarExists: 'includes("${{BREW_NAME}}", "{{BREW_NAME}}") == false' |
| 263 | + |
| 264 | + |
| 265 | + push_prod: |
| 266 | + stage: Release |
| 267 | + title: promote image |
| 268 | + type: push |
| 269 | + candidate: ${{build}} |
| 270 | + tags: |
| 271 | + - latest |
| 272 | + - ${{VERSION}} |
| 273 | + when: |
| 274 | + condition: |
| 275 | + all: |
| 276 | + isBinary: '"${{REPO_TYPE}}" != "lib"' |
| 277 | + steps: |
| 278 | + - name: create_release_bin |
| 279 | + on: |
| 280 | + - success |
| 281 | + branch: |
| 282 | + only: ["main"] |
| 283 | + scale: |
| 284 | + push_quay: |
| 285 | + title: push to quay |
| 286 | + registry: "${{REGISTRY_INTEGRATION_QUAY}}" |
0 commit comments