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 18 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 1 addition & 10 deletions .github/workflows/analyse-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@ env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.DHIS2_BOT_SONARCLOUD_TOKEN }}
on:
push:
branches:
- master
- "2.3[1-9]"
- "2.4[0-9]"
pull_request:
branches:
- master
- "2.3[1-9]"
- "2.4[0-9]"
workflow_dispatch: # Only manual trigger, no automatic triggers
concurrency:
group: ${{ github.workflow}}-${{ github.ref }}
cancel-in-progress: true
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/check-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ env:
# This is to make sure Maven don't timeout fetching dependencies. See: https://github.com/actions/virtual-environments/issues/1499
MAVEN_OPTS: -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.http.retryHandler.class=standard -Dmaven.wagon.http.retryHandler.count=3 -Dmaven.wagon.httpconnectionManager.ttlSeconds=125

on: [ pull_request ]
on:
workflow_dispatch: # Only manual trigger, no automatic triggers

jobs:
check-formatting:
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ env:
MAVEN_OPTS: -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.http.retryHandler.class=standard -Dmaven.wagon.http.retryHandler.count=3 -Dmaven.wagon.httpconnectionManager.ttlSeconds=125

on:
pull_request:
branches:
- master
workflow_dispatch: # Only manual trigger, no automatic triggers
schedule:
- cron: "0 12 * * *"
concurrency:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Dependabot auto-merge

on:
pull_request:
workflow_dispatch: # Only manual trigger, no automatic triggers

permissions:
pull-requests: write
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/deploy-instance.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: Deploy instance

on:
pull_request:
types: [opened, reopened, labeled, synchronize]
workflow_dispatch: # Only manual trigger, no automatic triggers

# Cancel previous runs of the same workflow and PR number or branch/tag
concurrency:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/destroy-instance.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: Destroy instance

on:
pull_request:
types: [closed, unlabeled]
workflow_dispatch: # Only manual trigger, no automatic triggers

# Cancel previous runs of the same workflow and PR number or branch/tag
concurrency:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/run-api-analytics-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ env:
MAVEN_OPTS: -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.http.retryHandler.class=standard -Dmaven.wagon.http.retryHandler.count=3 -Dmaven.wagon.httpconnectionManager.ttlSeconds=125

on:
pull_request:
types: [opened, labeled, synchronize]
workflow_dispatch: # Only manual trigger, no automatic triggers
schedule:
- cron: "16 1 * * *" # Run at 01:16 AM
concurrency:
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/run-api-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ env:
MAVEN_OPTS: -Xmx1024m -Xms1024m -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.http.retryHandler.class=standard -Dmaven.wagon.http.retryHandler.count=3 -Dmaven.wagon.httpconnectionManager.ttlSeconds=125

on:
push:
branches:
- master
pull_request:
workflow_dispatch: # Only manual trigger, no automatic triggers
concurrency:
group: ${{ github.workflow}}-${{ github.ref }}
cancel-in-progress: true
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ env:
# This is to make sure Maven don't timeout fetching dependencies. See: https://github.com/actions/virtual-environments/issues/1499
MAVEN_OPTS: -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.http.retryHandler.class=standard -Dmaven.wagon.http.retryHandler.count=3 -Dmaven.wagon.httpconnectionManager.ttlSeconds=125
on:
push:
branches:
- master
pull_request:
workflow_dispatch: # Only manual trigger, no automatic triggers
concurrency:
group: ${{ github.workflow}}-${{ github.ref }}
cancel-in-progress: true
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/update-instance-manager.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Update instance manager

on:
pull_request:
# For this to work, this workflow needs to be on master https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#workflow_run
# workflow_run:
# workflows: ["Check formatting"]
# types:
# - completed

jobs:
say-hello:
runs-on: ubuntu-latest
env:
GIT_COMMIT: ${{ github.sha }} # Declare GIT_COMMIT for the entire job

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin

# Set up Maven
- name: Set up Maven
run: |
sudo apt-get install maven
echo "On branch: $GITHUB_HEAD_REF"
echo "Git commit: $GIT_COMMIT"

# Run Maven build
- 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 ..."
echo "Version: ${GITHUB_REF#refs/heads/}"
chmod +x ./dhis-2/gha-copy-war-s3.sh
./dhis-2/gha-copy-war-s3.sh dev $GITHUB_HEAD_REF
130 changes: 130 additions & 0 deletions dhis-2/gha-copy-war-s3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/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")

echo "Release verion: $RELEASE_VERSION"
echo "Major version: $MAJOR_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
17 changes: 10 additions & 7 deletions jenkinsfiles/dev
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pipeline {
}
}

stage('Run api tests') {
/* stage('Run api tests') {
environment {
RP_UUID = credentials('report-portal-access-uuid')
RP_ENABLE = 'true'
Expand Down Expand Up @@ -100,15 +100,18 @@ pipeline {
}
}
}
}
}*/

stage('Sync WAR') {
steps {
implementIoBuildStarted(buildName: "${STAGE_NAME}")
echo 'Syncing WAR ...'
sh 'curl "https://raw.githubusercontent.com/dhis2/dhis2-server-setup/master/ci/scripts/copy-war-s3.sh" -O'
sh 'chmod +x copy-war-s3.sh'
sh './copy-war-s3.sh dev ${GIT_BRANCH}'
//sh 'curl "https://raw.githubusercontent.com/dhis2/dhis2-server-setup/master/ci/scripts/copy-war-s3.sh" -O'
//sh 'chmod +x copy-war-s3.sh'
//sh './copy-war-s3.sh dev ${GIT_BRANCH}'

sh 'chmod +x ./dhis-2/gha-copy-war-s3.sh'
sh './dhis-2/gha-copy-war-s3.sh dev $GIT_BRANCH'
}

post {
Expand All @@ -118,7 +121,7 @@ pipeline {
}
}

stage('Publish image') {
/* stage('Publish image') {
environment {
// THIS MUST be kept in sync with the jib.from.image in ../dhis-2/dhis-web-server/pom.xml
BASE_IMAGE = "tomcat:10.1.30-jre17"
Expand Down Expand Up @@ -197,7 +200,7 @@ pipeline {
}
}
}
}
}*/
}

post {
Expand Down
Loading