Skip to content

Commit

Permalink
GitHub workflow 'container-auto-update.yml': Add end-of-life check
Browse files Browse the repository at this point in the history
Since we're sometimes supporting PHP branches that already reached end-of-life, we allow manually disabling this check.
  • Loading branch information
PhrozenByte committed Jul 8, 2023
1 parent cc40a3a commit 381ec25
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/container-auto-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,14 @@ jobs:
- name: Generate container image tags
run: |
source <(./tags.sh "$GITHUB_RUN_ID.$GITHUB_RUN_NUMBER")
echo "MILESTONE=$MILESTONE" | tee -a "$GITHUB_ENV"
echo "VERSION=$VERSION" | tee -a "$GITHUB_ENV"
echo "TAGS=$TAGS" | tee -a "$GITHUB_ENV"
- name: Check end of life
run: |
./check-end-of-life.sh
- name: Check for updates
run: |
BUILD_ACTION="$(./check-for-updates.sh)"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/container-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ jobs:
- name: Generate container image tags
run: |
source <(./tags.sh "$GITHUB_RUN_ID.$GITHUB_RUN_NUMBER")
echo "MILESTONE=$MILESTONE" | tee -a "$GITHUB_ENV"
echo "VERSION=$VERSION" | tee -a "$GITHUB_ENV"
echo "TAGS=$TAGS" | tee -a "$GITHUB_ENV"
Expand Down
1 change: 1 addition & 0 deletions branches/7.3/container.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
MILESTONE="7.3"
VERSION="${VERSION:-$MILESTONE}"
VERSION_ENDOFLIFE="yes"
VERSION_ALPINE="3.15"

REGISTRY="${REGISTRY:-ghcr.io}"
Expand Down
1 change: 1 addition & 0 deletions branches/7.4/container.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
MILESTONE="7.4"
VERSION="${VERSION:-$MILESTONE}"
VERSION_ENDOFLIFE="yes"
VERSION_ALPINE="3.16"

REGISTRY="${REGISTRY:-ghcr.io}"
Expand Down
1 change: 1 addition & 0 deletions branches/8.0/container.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
MILESTONE="8.0"
VERSION="${VERSION:-$MILESTONE}"
VERSION_ENDOFLIFE="no"
VERSION_ALPINE="3.16"

REGISTRY="${REGISTRY:-ghcr.io}"
Expand Down
1 change: 1 addition & 0 deletions branches/8.1/container.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
MILESTONE="8.1"
VERSION="${VERSION:-$MILESTONE}"
VERSION_ENDOFLIFE="no"
VERSION_ALPINE="3.16"

REGISTRY="${REGISTRY:-ghcr.io}"
Expand Down
1 change: 1 addition & 0 deletions branches/8.2/container.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
MILESTONE="8.2"
VERSION="${VERSION:-$MILESTONE}"
VERSION_ENDOFLIFE="no"
VERSION_ALPINE="3.18"

REGISTRY="${REGISTRY:-ghcr.io}"
Expand Down
95 changes: 95 additions & 0 deletions check-end-of-life.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash
# php-fpm
# A php-fpm container with an improved configuration.
#
# Copyright (c) 2021 SGS Serious Gaming & Simulations GmbH
#
# This work is licensed under the terms of the MIT license.
# For a copy, see LICENSE file or <https://opensource.org/licenses/MIT>.
#
# SPDX-License-Identifier: MIT
# License-Filename: LICENSE

set -eu -o pipefail
export LC_ALL=C.UTF-8

[ -v CI_TOOLS ] && [ "$CI_TOOLS" == "SGSGermany" ] \
|| { echo "Invalid build environment: Environment variable 'CI_TOOLS' not set or invalid" >&2; exit 1; }

[ -v CI_TOOLS_PATH ] && [ -d "$CI_TOOLS_PATH" ] \
|| { echo "Invalid build environment: Environment variable 'CI_TOOLS_PATH' not set or invalid" >&2; exit 1; }

[ -x "$(which jq)" ] \
|| { echo "Invalid build environment: Missing runtime dependency: jq" >&2; exit 1; }

[ -x "$(which curl)" ] \
|| { echo "Invalid build environment: Missing runtime dependency: curl" >&2; exit 1; }

source "$CI_TOOLS_PATH/helper/common.sh.inc"
source "$CI_TOOLS_PATH/helper/git.sh.inc"

BUILD_DIR="$(CDPATH= cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"

if [ -v MILESTONE ]; then
if [ ! -f "$BUILD_DIR/branches/$MILESTONE/container.env" ]; then
echo "Invalid build environment: Invalid environment variable 'MILESTONE':" \
"Container environment file '$BUILD_DIR/branches/$MILESTONE/container.env' not found" >&2
exit 1
fi

source "$BUILD_DIR/branches/$MILESTONE/container.env"
else
source "$BUILD_DIR/container.env"
fi

if [ "$VERSION" != "$MILESTONE" ] && [[ "$VERSION" != "$MILESTONE".* ]]; then
echo "Invalid build environment: Invalid environment variable 'MILESTONE':" \
"Version '$VERSION' is no part of the '$MILESTONE' branch" >&2
exit 1
fi

# request PHP version info from php.net
VERSION_URL="https://www.php.net/releases/index.php?json&version=$MILESTONE"

echo + "VERSION_JSON=\"\$(curl -sSL -o - $(quote "$VERSION_URL"))\"" >&2
VERSION_JSON="$(curl -sSL -o - "$VERSION_URL")"

if [ -z "$VERSION_JSON" ]; then
echo "Unable to determine PHP support status: HTTP request '$VERSION_URL' failed" >&2
return 1
elif ! jq -e '.' > /dev/null 2>&1 <<< "$VERSION_JSON"; then
echo "Unable to determine PHP support status: HTTP request '$VERSION_URL' returned a malformed response: $(head -n1 <<< "$VERSION_JSON")" >&2
return 1
fi

# print PHP support status
EXIT_CODE=0

echo + "SUPPORT_STATUS=\"\$(jq -r --arg BRANCH $(quote "$MILESTONE") 'any(.supported_versions[] == \$BRANCH; .)' <<< \"\$VERSION_JSON\")"\" >&2
SUPPORT_STATUS="$(jq -r --arg BRANCH "$MILESTONE" 'any(.supported_versions[] == $BRANCH; .)' <<< "$VERSION_JSON")"

echo + "[ $(quote "$SUPPORT_STATUS") == true ]" >&2
if [ "$SUPPORT_STATUS" == "true" ]; then
echo "PHP $MILESTONE is still supported"
else
echo + "[ $(quote "$SUPPORT_STATUS") == false ]" >&2
if [ "$SUPPORT_STATUS" != "false" ]; then
echo "Unable to determine PHP support status: Invalid API response" >&2
exit 1
fi

echo "PHP $MILESTONE has reached its end of life"
EXIT_CODE=1
fi

LATEST_VERSION="$(jq -r '.version // empty' <<< "$VERSION_JSON")"
LATEST_VERSION_DATE="$(jq -r '.date // empty' <<< "$VERSION_JSON")"
[ -z "$LATEST_VERSION" ] || [ -z "$LATEST_VERSION_DATE" ] \
|| echo "The latest version $LATEST_VERSION was released on $(date --date="$LATEST_VERSION_DATE" +%Y-%m-%d)"

if [ $EXIT_CODE -ne 0 ] && [ "$VERSION_ENDOFLIFE" == "yes" ]; then
echo "Ignoring error, branch is expected to be end-of-life"
exit 0
fi

exit $EXIT_CODE
1 change: 1 addition & 0 deletions container.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
MILESTONE="${MILESTONE:-8.2}"
VERSION="${VERSION:-$MILESTONE}"
VERSION_ENDOFLIFE="${VERSION_ENDOFLIFE:-no}"
VERSION_ALPINE="${VERSION_ALPINE:-3.18}"

REGISTRY="${REGISTRY:-ghcr.io}"
Expand Down
1 change: 1 addition & 0 deletions tags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,6 @@ if [ "$VERSION" == "$VERSION_LATEST_MINOR" ]; then
fi
fi

printf 'MILESTONE="%s"\n' "$VERSION_MINOR"
printf 'VERSION="%s"\n' "$VERSION"
printf 'TAGS="%s"\n' "${TAGS[*]}"
8 changes: 6 additions & 2 deletions versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ php_local_branches() {
php_global_branches() {
local VERSION_URL="https://www.php.net/releases/index.php?json"

local VERSION_JSON="$(curl -sSL -f -o - "$VERSION_URL")"
local VERSION_JSON="$(curl -sSL -o - "$VERSION_URL")"
if [ -z "$VERSION_JSON" ]; then
echo "Unable to read supported PHP branches: HTTP request '$VERSION_URL' failed" >&2
return 1
Expand Down Expand Up @@ -92,7 +92,7 @@ php_latest_global_version() {
local VERSION_URL="https://www.php.net/releases/index.php?json"
[ -z "$BRANCH" ] || VERSION_URL+="&max=1&version=$BRANCH"

local VERSION_JSON="$(curl -sSL -f -o - "$VERSION_URL")"
local VERSION_JSON="$(curl -sSL -o - "$VERSION_URL")"
if [ -z "$VERSION_JSON" ]; then
echo "Unable to read latest PHP version: HTTP request '$VERSION_URL' failed" >&2
return 1
Expand Down Expand Up @@ -170,8 +170,12 @@ VERSION_LATEST_GLOBAL_MINOR="$(php_latest_global_version "$VERSION_MINOR")"
echo + "VERSION_LATEST_GLOBAL_MAJOR=\"\$(php_latest_global_version $(quote "$VERSION_MAJOR"))\"" >&2
VERSION_LATEST_GLOBAL_MAJOR="$(php_latest_global_version "$VERSION_MAJOR")"

echo + "SUPPORT_STATUS=\"\$(grep -q -F $(quote "$VERSION_MINOR") <<< \"\$BRANCHES_GLOBAL\" && echo \"Supported\" || echo \"End of life\")\"" >&2
SUPPORT_STATUS="$(grep -q -F "$VERSION_MINOR" <<< "$BRANCHES_GLOBAL" && echo "Supported" || echo "End of life")"

echo "Milestone: $MILESTONE"
echo "Version: $VERSION"
echo "Status: $SUPPORT_STATUS"
echo

echo "Versions according to ./vendor/versions.json"
Expand Down

0 comments on commit 381ec25

Please sign in to comment.