mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-21 05:31:06 -05:00
build: fix build metadata (#6015)
- Don't set BUILD_VERSION in CI/CD workflows otherwise the build-metadata script will always fall back to those values instead of computing new ones. - When calculating BUILD_REVISION, check if BUILD_REVISION is set before falling back.
This commit is contained in:
parent
bde3b9368e
commit
82094c879b
3 changed files with 12 additions and 5 deletions
4
.github/workflows/cd.yml
vendored
4
.github/workflows/cd.yml
vendored
|
@ -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
|
||||
|
|
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue