diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 130ffc9c..d30e9003 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -34,15 +34,15 @@ jobs: steps: - name: Checkout Code uses: actions/checkout@v4 + with: + fetch-depth: 2 - name: Set build metadata run: | if [[ ${{ github.event_name }} == 'push' ]] || [[ ${{ github.event_name }} == 'merge_group' ]]; then BUILD_REVISION=${{ github.sha }} - BUILD_VERSION=${{ github.sha }} elif [[ ${{ github.event_name }} == 'pull_request' ]]; then BUILD_REVISION=${{ github.event.pull_request.head.sha }} - BUILD_VERSION=${{ github.event.pull_request.head.sha }} else echo "[ERROR] Event not supported when setting build revision and build version" exit 1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 965c13e6..ec5ae62b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,16 +27,16 @@ jobs: steps: - name: Checkout Code uses: actions/checkout@v4 + with: + fetch-depth: 2 - name: Set build metadata id: set-container-image-build-metadata run: | if [[ ${{ github.event_name }} == 'push' ]] || [[ ${{ github.event_name }} == 'merge_group' ]]; then BUILD_REVISION=${{ github.sha }} - BUILD_VERSION=${{ github.sha }} elif [[ ${{ github.event_name }} == 'pull_request' ]]; then BUILD_REVISION=${{ github.event.pull_request.head.sha }} - BUILD_VERSION=${{ github.event.pull_request.head.sha }} else echo "[ERROR] Event not supported when setting build revision and build version" exit 1 diff --git a/scripts/build-metadata.sh b/scripts/build-metadata.sh index 0dc6ed4a..f5624a52 100755 --- a/scripts/build-metadata.sh +++ b/scripts/build-metadata.sh @@ -9,7 +9,12 @@ GetBuildDate() { } GetBuildRevision() { - git rev-parse HEAD + if [[ -v BUILD_REVISION ]]; then + # BUILD_REVISION is already set, no need to compute it + echo "${BUILD_REVISION}" + else + git rev-parse HEAD + fi } GetBuildVersion() { @@ -21,6 +26,8 @@ GetBuildVersion() { if git diff-tree --no-commit-id --name-only -r "${BUILD_REVISION}" | grep -q "${VERSION_FILE_PATH}"; then cat "${VERSION_FILE_PATH}" else + # Fallback on the build revision to avoid that a non-release container image + # has BUILD_VERSION set to a release string GetBuildRevision fi }