Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task: Test first GHA workflow [DHIS2-18615] #19464

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
task: Use self scipt to copy war to S3 [DHIS2-18615]
  • Loading branch information
muilpp committed Dec 16, 2024
commit ba685f6b8bc731fe59529f246e9336d2d705c8f1
128 changes: 128 additions & 0 deletions .github/workflows/gha-copy-war-s3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/usr/bin/env bash

# This script is used in the pipelines for all the supported dhis2-core branches, including
# master and 4 major versions before that and for all the build types - dev, canary, eos and stable.

set -euo pipefail

BUILD_DATE=$(date -I'date')

IS_PATCH_VERSION=0

VERSIONS_JSON="https://releases.dhis2.org/v1/versions/stable.json"

BUCKET="s3://releases.dhis2.org"

S3_CMD="aws s3 cp --metadata git-commit=$GIT_COMMIT --no-progress"

S3_DESTINATIONS=()

RELEASE_TYPE="$1"

if [[ -z "$1" ]]; then
echo "Error: Release type is required."
exit 1
fi

RELEASE_VERSION="$2"

if [[ -z "$2" ]]; then
echo "Error: Release version is required."
exit 1
fi

MAJOR_VERSION=$(cut -d '.' -f 2 <<< "$RELEASE_VERSION")

if [[ "$RELEASE_VERSION" == "master" || $MAJOR_VERSION -ge 42 ]]; then
WAR_LOCATION="${WORKSPACE}/dhis-2/dhis-web-server/target/dhis.war"
else
WAR_LOCATION="${WORKSPACE}/dhis-2/dhis-web/dhis-web-portal/target/dhis.war"
fi

if [[ ! -f "$WAR_LOCATION" ]]; then
echo "Error: WAR file not found."
exit 1
fi

case $RELEASE_TYPE in
"canary")
S3_DESTINATIONS+=("$BUCKET/$RELEASE_VERSION/$RELEASE_TYPE/dhis2-$RELEASE_TYPE-$RELEASE_VERSION.war")

S3_DESTINATIONS+=("$BUCKET/$RELEASE_VERSION/$RELEASE_TYPE/dhis2-$RELEASE_TYPE-$RELEASE_VERSION-$BUILD_DATE.war")
;;

"dev")
S3_DESTINATIONS+=("$BUCKET/$RELEASE_VERSION/$RELEASE_TYPE/dhis2-$RELEASE_TYPE-$RELEASE_VERSION.war")

if [[ "$RELEASE_VERSION" == "master" ]]; then
RELEASE_VERSION="dev"
fi

S3_DESTINATIONS+=("$BUCKET/$RELEASE_VERSION/dhis.war")
;;

"eos")
S3_DESTINATIONS+=("$BUCKET/$RELEASE_VERSION/dhis2-stable-$RELEASE_VERSION-$RELEASE_TYPE.war")
;;

"stable")
if [[ "$RELEASE_VERSION" =~ ^patch\/.* ]]; then
IS_PATCH_VERSION=1
RELEASE_VERSION=${RELEASE_VERSION#"patch/"}
fi

SHORT_VERSION=$(cut -d '.' -f 1,2 <<< "$RELEASE_VERSION")

PATCH_VERSION=$(cut -d '.' -f 3 <<< "$RELEASE_VERSION")

# Add an extra destination in S3 for the new semantic version schema without leading "2."
IFS=. read -ra RELEASE_VERSION_SEGMENTS <<< "$RELEASE_VERSION"

NEW_RELEASE_VERSION=$(cut -d '.' -f 2- <<< "$RELEASE_VERSION")
NEW_SHORT_VERSION=$(cut -d '.' -f 2 <<< "$RELEASE_VERSION")

if [[ "$IS_PATCH_VERSION" -eq 1 ]]; then
RELEASE_VERSION+="-rc"
# for release candidates, also add a version with the git hash
S3_DESTINATIONS+=("$BUCKET/$SHORT_VERSION/dhis2-$RELEASE_TYPE-$RELEASE_VERSION-${GIT_COMMIT:0:7}.war")
fi

S3_DESTINATIONS+=("$BUCKET/$SHORT_VERSION/dhis2-$RELEASE_TYPE-$RELEASE_VERSION.war")
S3_DESTINATIONS+=("$BUCKET/$SHORT_VERSION/$RELEASE_VERSION/dhis.war")

LATEST_PATCH_VERSION=$(
curl -fsSL "$VERSIONS_JSON" |
jq -r --arg VERSION "$SHORT_VERSION" '.versions[] | select(.name == $VERSION ) | .latestPatchVersion'
)

if [[ "$IS_PATCH_VERSION" -eq 0 && -n "${LATEST_PATCH_VERSION-}" && "$PATCH_VERSION" -ge "$LATEST_PATCH_VERSION" ]]; then
S3_DESTINATIONS+=("$BUCKET/$SHORT_VERSION/dhis2-$RELEASE_TYPE-latest.war")
S3_DESTINATIONS+=("$BUCKET/$NEW_SHORT_VERSION/dhis2-$RELEASE_TYPE-latest.war")
fi


if [[ ${#RELEASE_VERSION_SEGMENTS[@]} -lt 4 ]]; then
NEW_RELEASE_VERSION+=".0"
fi

if [[ "$IS_PATCH_VERSION" -eq 1 ]]; then
NEW_RELEASE_VERSION+="-rc"
# for release candidates, also add a version with the git hash
S3_DESTINATIONS+=("$BUCKET/$NEW_SHORT_VERSION/dhis2-$RELEASE_TYPE-$NEW_RELEASE_VERSION-${GIT_COMMIT:0:7}.war")
fi

S3_DESTINATIONS+=("$BUCKET/$NEW_SHORT_VERSION/dhis2-$RELEASE_TYPE-$NEW_RELEASE_VERSION.war")

;;

*)
echo "Error: Unknown Release type."
exit 1
;;
esac

for destination in "${S3_DESTINATIONS[@]}"
do
#echo "$WAR_LOCATION" "$destination"
$S3_CMD "$WAR_LOCATION" "$destination"
done
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Hello World Pipeline
name: Update instance manager

on:
pull_request:
Expand Down Expand Up @@ -33,9 +33,10 @@ jobs:
- name: Build with Maven
run: mvn --threads 4 --batch-mode --no-transfer-progress clean install --update-snapshots --file ./dhis-2/pom.xml -DskipTests

#curl "https://raw.githubusercontent.com/dhis2/dhis2-server-setup/master/ci/scripts/copy-war-s3.sh" -O
- name: Sync war
run: |
echo "Syncing WAR ..."
curl "https://raw.githubusercontent.com/dhis2/dhis2-server-setup/master/ci/scripts/copy-war-s3.sh" -O
chmod +x copy-war-s3.sh
./copy-war-s3.sh dev $GITHUB_HEAD_REF

chmod +x gha-copy-war-s3.sh
./gha-copy-war-s3.sh dev $GITHUB_HEAD_REF
Loading