@@ -345,14 +345,29 @@ jobs:
345
345
with :
346
346
crate : cargo-edit
347
347
bin : cargo-set-version
348
+ - name : Update version if PR against main branch
349
+ if : ${{ github.event_name == 'pull_request' && github.ref == 'refs/heads/main' }}
350
+ run : cargo set-version --offline --workspace 0.0.0-pr${{ github.event.pull_request.number }}
351
+ - name : Update version if PR against non-main branch
352
+ # For PRs to be merged against a release branch, use the version that has already been set in the calling script.
353
+ # We can't rely on cargo set-version here as we will break semver rules when changing the version to make it
354
+ # specific to this PR e.g. 1.2.0 --> 1.2.0-pr678, so set it manually.
355
+ if : ${{ github.event_name == 'pull_request' && github.ref != 'refs/heads/main' }}
356
+ env :
357
+ PR_NUMBER : ${{ github.event.pull_request.number }}
358
+ run : |
359
+ MANIFEST_VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[0].version')
360
+ PR_VERSION="${MANIFEST_VERSION}-pr${PR_NUMBER}"
361
+ sed -i "s/version = \"${MANIFEST_VERSION}\"/version = \"${PR_VERSION}\"/" Cargo.toml
362
+
348
363
# Recreate charts and publish charts and docker image. The "-e" is needed as we want to override the
349
364
# default value in the makefile if called from this action, but not otherwise (i.e. when called locally).
350
365
# This is needed for the HELM_REPO variable.
351
366
- name : Install cosign
352
367
uses : sigstore/cosign-installer@4959ce089c160fddf62f7b42464195ba1a56d382 # v3.6.0
353
368
- name : Install syft
354
369
uses : anchore/sbom-action/download-syft@61119d458adab75f756bc0b9e4bde25725f86a7a # v0.17.2
355
- - name : Build prerequisites
370
+ - name : Build Docker image and Helm chart
356
371
run : |
357
372
# Installing helm and yq on ubicloud-standard-8-arm only
358
373
if [ "$(arch)" = "aarch64" ]; then
@@ -362,29 +377,8 @@ jobs:
362
377
sudo apt-get -y install helm
363
378
sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_arm64 -O /usr/bin/yq && sudo chmod +x /usr/bin/yq
364
379
fi
365
- - name : Build Docker image and Helm chart - main-PR
366
- if : ${{ github.event_name == 'pull_request' && github.ref == 'refs/heads/main' }}
367
- env :
368
- PR_NUMBER : ${{ github.event.pull_request.number }}
369
- run : |
370
- PR_VERSION="0.0.0-pr${PR_NUMBER}"
371
-
372
- make -e build PR_VERSION="$PR_VERSION"
373
- - name : Build Docker image and Helm chart - non-main-PR
374
- if : ${{ github.event_name == 'pull_request' && github.ref != 'refs/heads/main' }}
375
- env :
376
- PR_NUMBER : ${{ github.event.pull_request.number }}
377
- run : |
378
- MANIFEST_VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[0].version')
379
- PR_VERSION="${MANIFEST_VERSION}-pr${PR_NUMBER}"
380
-
381
- make -e build PR_VERSION="$PR_VERSION"
382
- - name : Build Docker image and Helm chart - non-PR
383
- if : ${{ github.event_name != 'pull_request' }}
384
- run : |
385
- PR_VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[0].version')
386
380
387
- make -e build PR_VERSION="$PR_VERSION"
381
+ make -e build
388
382
- name : Publish Docker image and Helm chart
389
383
if : ${{ !github.event.pull_request.head.repo.fork }}
390
384
run : |
0 commit comments