This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
.github/workflows/build.yml #1380
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: build images | |
on: | |
push: | |
branches-ignore: | |
- 'dependabot/**' | |
- 'manual-dependencies/**' | |
paths-ignore: | |
- '.env.example' | |
- '.github/dependabot.yml' | |
- '.github/workflows/dependencies.yml' | |
- '.gitignore' | |
- 'LICENSE' | |
- 'README.md' | |
pull_request: | |
branches: | |
- main | |
paths-ignore: | |
- '.env.example' | |
- '.github/dependabot.yml' | |
- '.github/workflows/dependencies.yml' | |
- '.gitignore' | |
- 'LICENSE' | |
- 'README.md' | |
schedule: | |
- cron: '28 3 * * *' | |
# Cancel existing executions when new commits are pushed onto the same branch | |
# (Source: https://ashishb.net/tech/common-pitfalls-of-github-actions/) | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
defaults: | |
run: | |
shell: bash | |
# Use "env" to set workflow-level variables. | |
# NOTE: This can't be used by "jobs[*].container"; see "jobs.set_defaults" to use outputs as a workaround. | |
env: | |
BASEIMAGE_11: docker.io/library/tomcat:9-jre11-temurin-jammy | |
BASEIMAGE_17: docker.io/library/tomcat:9-jre17-temurin-jammy | |
jobs: | |
set_defaults: | |
name: Set defaults | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 3 | |
steps: | |
# It is not currently possible to use a global env for jobs.baseimage_query.container. | |
# Because we may want to support alternate versions of Tomcat and Java in the future, | |
# we will set it a single time in this job and pass the value as an output. | |
- name: Set default base images | |
id: default_base_images | |
run: | | |
set -x | |
echo "base_image_11=$BASEIMAGE_11" >> $GITHUB_OUTPUT | |
echo "base_image_17=$BASEIMAGE_17" >> $GITHUB_OUTPUT | |
outputs: | |
base_image_11: ${{ steps.default_base_images.outputs.base_image_11 }} | |
base_image_17: ${{ steps.default_base_images.outputs.base_image_17 }} | |
baseimage_11_query: | |
name: Versions in Java 11 base image | |
needs: set_defaults | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 3 | |
container: ${{ needs.set_defaults.outputs.base_image_11 }} # NOTE: This cannot be ${{ env.EXAMPLE }} or ${{ matrix.example }} | |
steps: | |
- name: Query versions of Java and Tomcat in the Java 11 base image | |
id: tomcat_query | |
run: | | |
set -x | |
echo "java_version=$( sed --regexp-extended --expression='s/^(jdk|jre)-?//' <<< "$JAVA_VERSION" )" >> $GITHUB_OUTPUT | |
echo "tomcat_major=$TOMCAT_MAJOR" >> $GITHUB_OUTPUT | |
echo "tomcat_version=$TOMCAT_VERSION" >> $GITHUB_OUTPUT | |
outputs: | |
java_version: ${{ steps.tomcat_query.outputs.java_version }} | |
tomcat_major: ${{ steps.tomcat_query.outputs.tomcat_major }} | |
tomcat_version: ${{ steps.tomcat_query.outputs.tomcat_version }} | |
baseimage_17_query: | |
name: Versions in Java 17 base image | |
needs: set_defaults | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 3 | |
container: ${{ needs.set_defaults.outputs.base_image_17 }} # NOTE: This cannot be ${{ env.EXAMPLE }} or ${{ matrix.example }} | |
steps: | |
- name: Query versions of Java and Tomcat in the Java 17 base image | |
id: tomcat_query | |
run: | | |
set -x | |
echo "java_version=$( sed --regexp-extended --expression='s/^(jdk|jre)-?//' <<< "$JAVA_VERSION" )" >> $GITHUB_OUTPUT | |
echo "tomcat_major=$TOMCAT_MAJOR" >> $GITHUB_OUTPUT | |
echo "tomcat_version=$TOMCAT_VERSION" >> $GITHUB_OUTPUT | |
outputs: | |
java_version: ${{ steps.tomcat_query.outputs.java_version }} | |
tomcat_major: ${{ steps.tomcat_query.outputs.tomcat_major }} | |
tomcat_version: ${{ steps.tomcat_query.outputs.tomcat_version }} | |
generate_matrix: | |
name: Generate matrix of DHIS2 stable versions | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 3 | |
steps: | |
- name: Checkout repo to current directory | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | |
- name: Setup Python | |
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c | |
with: | |
python-version: '3.11' | |
- name: Install Python packages | |
run: | | |
set -x | |
pip3 install --requirement .github/workflows/support/matrix/requirements.txt | |
- name: Generate matrix for dev and stable versions | |
id: matrix_cmd | |
run: | | |
set -x | |
echo "dhis2_matrix=$( python3 .github/workflows/support/matrix/matrix.py )" >> $GITHUB_OUTPUT | |
outputs: | |
dhis2_matrix: ${{ steps.matrix_cmd.outputs.dhis2_matrix }} | |
build: | |
name: Build image | |
needs: | |
- baseimage_11_query | |
- baseimage_17_query | |
- generate_matrix | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 60 | |
services: | |
registry: | |
image: docker.io/library/registry:2 | |
ports: | |
- 5000:5000 | |
strategy: | |
matrix: ${{fromJSON(needs.generate_matrix.outputs.dhis2_matrix)}} | |
fail-fast: false | |
steps: | |
- name: Maximize build space | |
run: | | |
set -x | |
echo "Available storage:" | |
df -h | |
echo "Removing unwanted software... " | |
sudo rm -rf /usr/share/dotnet | |
sudo rm -rf /usr/local/lib/android | |
sudo rm -rf /opt/ghc | |
echo "Available storage:" | |
df -h | |
- name: Checkout this repository to source/ subdirectory | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | |
with: | |
path: source | |
- name: Download dhis.war to source/ subdirectory | |
id: get_war | |
run: | | |
set -x | |
# Trims full version like "2.36.1" or "2.36-dev" to "2.36" from job matrix | |
if grep --quiet --extended-regexp '^[0-9]{2}(\.|-)' <<< "${{ matrix.dhis2_version }}" ; then | |
DHIS2_MAJOR="$( cut -c1-2 <<< "${{ matrix.dhis2_version }}" )" | |
else | |
DHIS2_MAJOR="$( cut -c1-4 <<< "${{ matrix.dhis2_version }}" )" | |
fi | |
if [[ "$DHIS2_MAJOR" == "dev" ]] \ | |
&& [[ "${{ matrix.dhis2_version }}" == "dev" ]]; then | |
DHIS2_WAR_URL="https://releases.dhis2.org/$DHIS2_MAJOR/dhis.war" | |
elif [[ "${{ matrix.dhis2_version }}" =~ ^2\.[0-9]{2}-dev$ ]]; then | |
DHIS2_WAR_URL="https://releases.dhis2.org/$DHIS2_MAJOR/dev/dhis2-dev-${DHIS2_MAJOR}.war" | |
elif [[ "${{ matrix.dhis2_version }}" == "2.36.0" ]] || [[ "${{ matrix.dhis2_version }}" == "2.36.11" ]]; then | |
DHIS2_WAR_URL="https://s3.amazonaws.com/dhis2-builds/${{ matrix.dhis2_version }}/latest/dhis.war" | |
elif [[ "${{ matrix.dhis2_version }}" == "2.38.5" ]]; then `# S3 does not have a "dhis2-stable-2.38.5.0.war" file as linked to in stable.json` | |
DHIS2_WAR_URL="https://releases.dhis2.org/$DHIS2_MAJOR/dhis2-stable-${{ matrix.dhis2_version }}.war" | |
else | |
DHIS2_WAR_URL="$( curl -s https://releases.dhis2.org/v1/versions/stable.json | jq -r '.versions[] | .patchVersions[] | select(.name=="${{ matrix.dhis2_version }}") | .url' )" | |
fi | |
wget \ | |
--no-verbose \ | |
--output-document=source/dhis.war \ | |
"$DHIS2_WAR_URL" | |
# Expand to get the contents of build.properties | |
unzip -qq source/dhis.war -d source/dhis | |
DHIS2_BUILD_PROPERTIES="$( find source/dhis/WEB-INF/lib/ -name 'dhis-service-core-[0-9]*.jar' -exec unzip -p '{}' build.properties \; )" | |
echo "build_version=$( awk -F'=' '/^build\.version/ {gsub(/ /, "", $NF); print $NF}' <<< "$DHIS2_BUILD_PROPERTIES" )" >> $GITHUB_OUTPUT | |
echo "build_revision=$( awk -F'=' '/^build\.revision/ {gsub(/ /, "", $NF); print $NF}' <<< "$DHIS2_BUILD_PROPERTIES" )" >> $GITHUB_OUTPUT | |
echo "build_time=$( awk -F'=' '/^build\.time/ {sub(/ /, "", $NF); print $NF}' <<< "$DHIS2_BUILD_PROPERTIES" )" >> $GITHUB_OUTPUT | |
echo "build_date=$( awk -F'=' '/^build\.time/ {sub(/ /, "", $NF); print $NF}' <<< "$DHIS2_BUILD_PROPERTIES" | grep --only-matching --extended-regexp '20[0-9]{2}-[0-9]{2}-[0-9]{2}' )" >> $GITHUB_OUTPUT | |
- name: Version helper | |
id: versions_helper | |
run: | | |
set -x | |
# Trims full version like "2.36.1" or "2.36.7-SNAPSHOT" to "2.36" from war file build properties | |
if grep --quiet --extended-regexp '^[0-9]{2}(\.|-)' <<< "${{ steps.get_war.outputs.build_version }}" ; then | |
DHIS2_MAJOR="$( cut -c1-2 <<< "${{ steps.get_war.outputs.build_version }}" )" | |
else | |
DHIS2_MAJOR="$( cut -c1-4 <<< "${{ steps.get_war.outputs.build_version }}" )" | |
fi | |
echo "dhis2_major=$DHIS2_MAJOR" >> $GITHUB_OUTPUT | |
# 2.40 is co-branded as version 40. Generate alternate image tag values for all 2.40 releases | |
# Other versions will return the same values; duplicate tags will be normalized in steps.image_meta | |
if [[ '${{ matrix.dhis2_version }}' == '2.40-dev' ]] ; then | |
DHIS2_MAJOR_ALT='40' | |
DHIS2_VERSION_ALT='40-dev' | |
elif [[ "$DHIS2_MAJOR" == '2.40' ]] ; then | |
DHIS2_MAJOR_ALT='40' | |
DHIS2_VERSION_ALT="$( curl -s https://releases.dhis2.org/v1/versions/stable.json | jq -r '.versions[] | .patchVersions[] | select(.name=="${{ matrix.dhis2_version }}") | .url' | sed -e 's,^.*/dhis2-stable-,,' -e 's/\.war$//' )" | |
else | |
DHIS2_MAJOR_ALT="$DHIS2_MAJOR" | |
DHIS2_VERSION_ALT='${{ matrix.dhis2_version }}' | |
fi | |
echo "dhis2_major_alt=$DHIS2_MAJOR_ALT" >> $GITHUB_OUTPUT | |
echo "dhis2_version_alt=$DHIS2_VERSION_ALT" >> $GITHUB_OUTPUT | |
# If a version has builds for multiple versions of Java, mark one as the primary. As of this writing, matrix.py | |
# provides builds for Java 11 and 17 on DHIS2 2.39 and 2.40, but certain tags should only be added for 11. | |
DHIS2_PRIMARY_JAVA='true' | |
if [[ "$DHIS2_MAJOR" =~ 2\.(39|40) ]] && [[ '${{ matrix.java_major }}' == '17' ]]; then | |
DHIS2_PRIMARY_JAVA='false' | |
fi | |
echo "dhis2_primary_java=$DHIS2_PRIMARY_JAVA" >> $GITHUB_OUTPUT | |
# Trims full version with a _hotfix_ value like "2.36.10.1" or "2.36.10.1-SNAPSHOT", to a _maintenance_ value like "2.36.10" | |
# See https://dhis2-a3b1.kxcdn.com/uploads/default/original/3X/c/d/cd18b97ca7420000bd3c274c470cad01c63e24e5.jpeg | |
# or https://community.dhis2.org/t/hotfix-versioning-convention/47088 for details | |
if grep --quiet --only-matching --extended-regexp '^2\.[0-9]{2}\.[0-9]+\.[0-9]+.*' <<< "${{ matrix.dhis2_version }}" ; then | |
DHIS2_VERSION_MAINT="$( grep --only-matching --extended-regexp '^2\.[0-9]{2}\.[0-9]+' <<< "${{ matrix.dhis2_version }}" )" | |
else | |
DHIS2_VERSION_MAINT="${{ matrix.dhis2_version }}" | |
fi | |
echo "dhis2_version_maint=$DHIS2_VERSION_MAINT" >> $GITHUB_OUTPUT | |
# Due to limited GHA cache space, only retain Docker cache for one version | |
if ${{ matrix.latest_overall }}; then | |
echo "cache_to=type=gha,mode=max" >> $GITHUB_OUTPUT | |
fi | |
# Git checkout reference for e2e-tests repository | |
if [[ "${{ matrix.dhis2_version }}" == "dev" ]]; then | |
E2E_REMOTE_REF='master' | |
elif [[ "${{ matrix.dhis2_version }}" =~ ^2\.[0-9]{2}-dev$ ]]; then | |
# For a version like "2.37-dev", use "v37". If that doesn't exist, choose the latest as it is likely too new | |
if git ls-remote --heads --refs --sort='version:refname' https://github.com/dhis2/e2e-tests.git | awk '/[[:blank:]]+refs\/heads\/v[0-9]{2}$/ {gsub("refs/heads/",""); print $NF}' | grep "^v${DHIS2_MAJOR#2.}$" | |
then | |
E2E_REMOTE_REF="v${DHIS2_MAJOR#2.}" | |
else | |
E2E_REMOTE_REF="$( git ls-remote --heads --refs --sort='version:refname' https://github.com/dhis2/e2e-tests.git | awk '/[[:blank:]]+refs\/heads\/v[0-9]{2}$/ {gsub("refs/heads/",""); print $NF}' | sort --version-sort | tail -1 )" | |
fi | |
else | |
# The tag for a version may not exist in github.com/dhis2/e2e-tests, such as tag "2.37.0-rc" | |
# for version "2.37.1" as of this writing. This logic will determine the appropriate version | |
# if there is not an exact match. | |
if git ls-remote --tags --refs --sort='version:refname' https://github.com/dhis2/e2e-tests.git | awk '/[[:blank:]]+refs\/tags\/[0-9.]+-rc$/ {gsub("refs/tags/",""); print $NF}' | grep -q "^${{ matrix.dhis2_version }}-rc$" | |
then | |
E2E_REMOTE_REF="${{ matrix.dhis2_version }}-rc" | |
else | |
E2E_REMOTE_REF="$( git ls-remote --tags --refs --sort='version:refname' https://github.com/dhis2/e2e-tests.git | awk '/[[:blank:]]+refs\/tags\/[0-9.]+-rc$/ {gsub("refs/tags/",""); print $NF}'| grep "^${DHIS2_MAJOR}" | sort --version-sort | tail -1 )" | |
fi | |
fi | |
echo "e2e_remote_ref=$E2E_REMOTE_REF" >> $GITHUB_OUTPUT | |
# Git checkout depth for e2e-tests repository | |
if [[ "${{ matrix.dhis2_version }}" =~ ^2\.36\.[012]$ ]] ; then | |
echo "e2e_remote_depth=0" >> $GITHUB_OUTPUT | |
else | |
echo "e2e_remote_depth=1" >> $GITHUB_OUTPUT | |
fi | |
- name: Container image metadata | |
id: image_meta | |
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 | |
with: | |
images: ghcr.io/${{ github.repository_owner }}/dhis2 | |
labels: | | |
org.opencontainers.image.base.name=${{ env[format('BASEIMAGE_{0}', matrix.java_major)] }} | |
org.opencontainers.image.title=dhis2 | |
org.opencontainers.image.url=${{ github.server_url }}/${{ github.repository }}/pkgs/container/dhis2 | |
org.opencontainers.image.version=${{ matrix.dhis2_version }} | |
dhis2.build.major=${{ steps.versions_helper.outputs.dhis2_major }} | |
dhis2.build.version=${{ steps.get_war.outputs.build_version }} | |
dhis2.build.revision=${{ steps.get_war.outputs.build_revision }} | |
dhis2.build.time=${{ steps.get_war.outputs.build_time }} | |
dhis2.build.date=${{ steps.get_war.outputs.build_date }} | |
java.major=${{ matrix.java_major }} | |
java.version=${{ needs[format('baseimage_{0}_query', matrix.java_major)]['outputs']['java_version'] }} | |
tomcat.major=${{ needs[format('baseimage_{0}_query', matrix.java_major)]['outputs']['tomcat_major'] }} | |
tomcat.version=${{ needs[format('baseimage_{0}_query', matrix.java_major)]['outputs']['tomcat_version'] }} | |
flavor: latest=false | |
tags: | | |
type=raw,value=latest,enable=${{ matrix.latest_overall }} | |
type=raw,value=${{ steps.versions_helper.outputs.dhis2_major }},enable=${{ matrix.latest_major }} | |
type=raw,value=${{ matrix.dhis2_version }},enable=${{ steps.versions_helper.outputs.dhis2_primary_java }} | |
type=raw,value=${{ matrix.dhis2_version }}-jre${{ matrix.java_major }} | |
type=raw,value=${{ matrix.dhis2_version }}-tomcat${{ needs[format('baseimage_{0}_query', matrix.java_major)]['outputs']['tomcat_major'] }},enable=${{ steps.versions_helper.outputs.dhis2_primary_java }} | |
type=raw,value=${{ matrix.dhis2_version }}-tomcat${{ needs[format('baseimage_{0}_query', matrix.java_major)]['outputs']['tomcat_major'] }}-jre${{ matrix.java_major }} | |
type=raw,value=${{ matrix.dhis2_version }}-tomcat${{ needs[format('baseimage_{0}_query', matrix.java_major)]['outputs']['tomcat_version'] }}-jre${{ matrix.java_major }}-temurin-jammy | |
type=raw,value=${{ steps.versions_helper.outputs.dhis2_major_alt }},enable=${{ matrix.latest_major }} | |
type=raw,value=${{ steps.versions_helper.outputs.dhis2_version_alt }},enable=${{ steps.versions_helper.outputs.dhis2_primary_java }} | |
type=raw,value=${{ steps.versions_helper.outputs.dhis2_version_alt }}-jre${{ matrix.java_major }} | |
type=raw,value=${{ steps.versions_helper.outputs.dhis2_version_alt }}-tomcat${{ needs[format('baseimage_{0}_query', matrix.java_major)]['outputs']['tomcat_major'] }},enable=${{ steps.versions_helper.outputs.dhis2_primary_java }} | |
type=raw,value=${{ steps.versions_helper.outputs.dhis2_version_alt }}-tomcat${{ needs[format('baseimage_{0}_query', matrix.java_major)]['outputs']['tomcat_major'] }}-jre${{ matrix.java_major }} | |
type=raw,value=${{ steps.versions_helper.outputs.dhis2_version_alt }}-tomcat${{ needs[format('baseimage_{0}_query', matrix.java_major)]['outputs']['tomcat_version'] }}-jre${{ matrix.java_major }}-temurin-jammy | |
- name: Set up QEMU for amd64 and arm64 | |
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 | |
with: | |
platforms: linux/amd64,linux/arm64 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 | |
with: | |
driver-opts: network=host # Required for buildx container to push to local registry | |
- name: Multi-platform build and push to local registry | |
id: image_build | |
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 | |
with: | |
context: source # The default is to refer to the github.com sha URL, but we need the context as a directory for the downloaded dhis.war | |
file: source/Dockerfile # NOTE: A dhis.war file must be in the same directory as this file | |
platforms: linux/amd64,linux/arm64 | |
build-args: | | |
BASE_IMAGE=${{ env[format('BASEIMAGE_{0}', matrix.java_major)] }} | |
labels: ${{ steps.image_meta.outputs.labels }} | |
tags: localhost:5000/dhis2:${{ matrix.dhis2_version }}-${{ github.sha }} # The host:port in the tag determines the registry it's pushed to | |
pull: true | |
push: true | |
cache-from: type=gha | |
cache-to: ${{ steps.versions_helper.outputs.cache_to }} # https://github.community/t/do-expressions-support-ternary-operators-to-change-their-returned-value/18114/2 | |
- name: Inspect image in local registry | |
run: docker buildx imagetools inspect ${{ fromJSON(steps.image_build.outputs.metadata)['image.name'] }} | |
########################################################################## | |
- name: Use image from local registry in Compose | |
continue-on-error: ${{ endsWith(matrix.dhis2_version, 'dev') }} # don't block the remaining actions if it fails on dev versions | |
run: | | |
set -x | |
sed \ | |
--regexp-extended \ | |
--expression="/^\s+image:/ s,ghcr\.io/baosystems/dhis2[^\"]+,${{ fromJSON(steps.image_build.outputs.metadata)['image.name'] }},g" \ | |
--in-place \ | |
source/docker-compose.yml | |
- name: Pull Compose stack images | |
continue-on-error: ${{ endsWith(matrix.dhis2_version, 'dev') }} | |
run: | | |
set -x | |
docker compose \ | |
--project-name 'docker-dhis2' \ | |
--project-directory 'source' \ | |
--file 'source/docker-compose.yml' \ | |
--file 'source/.github/workflows/support/docker-compose.override.yml' \ | |
pull --quiet | |
- name: Create Compose stack and start database service | |
continue-on-error: ${{ endsWith(matrix.dhis2_version, 'dev') }} | |
run: | | |
set -x | |
docker compose \ | |
--project-name 'docker-dhis2' \ | |
--project-directory 'source' \ | |
--file 'source/docker-compose.yml' \ | |
--file 'source/.github/workflows/support/docker-compose.override.yml' \ | |
up --detach database | |
- name: Initialize the database | |
continue-on-error: ${{ endsWith(matrix.dhis2_version, 'dev') }} | |
run: | | |
set -x | |
sleep 6 | |
docker compose \ | |
--project-name 'docker-dhis2' \ | |
--project-directory 'source' \ | |
--file 'source/docker-compose.yml' \ | |
--file 'source/.github/workflows/support/docker-compose.override.yml' \ | |
exec database \ | |
psql --echo-all --echo-hidden -v 'ON_ERROR_STOP=1' --username='postgres' --dbname='postgres' --command='CREATE ROLE "dhis";' | |
docker compose \ | |
--project-name 'docker-dhis2' \ | |
--project-directory 'source' \ | |
--file 'source/docker-compose.yml' \ | |
--file 'source/.github/workflows/support/docker-compose.override.yml' \ | |
exec database \ | |
psql --echo-all --echo-hidden -v 'ON_ERROR_STOP=1' --username='postgres' --dbname='postgres' --command='CREATE DATABASE "dhis2";' | |
docker compose \ | |
--project-name 'docker-dhis2' \ | |
--project-directory 'source' \ | |
--file 'source/docker-compose.yml' \ | |
--file 'source/.github/workflows/support/docker-compose.override.yml' \ | |
exec database \ | |
psql --echo-all --echo-hidden -v 'ON_ERROR_STOP=1' --username='postgres' --dbname='dhis2' --command='CREATE EXTENSION postgis;' | |
- name: Import sample data | |
continue-on-error: ${{ endsWith(matrix.dhis2_version, 'dev') }} | |
run: | | |
set -x | |
if [[ "${{ matrix.dhis2_version }}" =~ ^2\.[0-9]{2}-dev$ ]]; then | |
DHIS2_DB_URL="https://databases.dhis2.org/sierra-leone/${{ steps.versions_helper.outputs.dhis2_major }}/dhis2-db-sierra-leone.sql.gz" | |
else | |
DHIS2_DB_URL="https://databases.dhis2.org/sierra-leone/${{ steps.versions_helper.outputs.dhis2_version_maint }}/dhis2-db-sierra-leone.sql.gz" | |
fi | |
wget \ | |
--no-verbose \ | |
--output-document=/tmp/db.sql.gz \ | |
"$DHIS2_DB_URL" | |
gunzip -c /tmp/db.sql.gz \ | |
| docker compose \ | |
--project-name 'docker-dhis2' \ | |
--project-directory 'source' \ | |
--file 'source/docker-compose.yml' \ | |
--file 'source/.github/workflows/support/docker-compose.override.yml' \ | |
exec -T database \ | |
psql -q -v 'ON_ERROR_STOP=1' --username='postgres' --dbname='dhis2' | |
- name: Start DHIS2 | |
continue-on-error: ${{ endsWith(matrix.dhis2_version, 'dev') }} | |
timeout-minutes: 15 | |
run: | | |
set -x | |
docker compose \ | |
--project-name 'docker-dhis2' \ | |
--project-directory 'source' \ | |
--file 'source/docker-compose.yml' \ | |
--file 'source/.github/workflows/support/docker-compose.override.yml' \ | |
up --detach | |
# Wait for login screen | |
set +x | |
until \ | |
curl -silent --output /dev/null --fail --max-time 1 http://localhost:8080/dhis-web-commons/security/login.action | |
do | |
sleep .5 | |
done | |
- name: Generate analytics | |
continue-on-error: ${{ endsWith(matrix.dhis2_version, 'dev') }} | |
timeout-minutes: 30 | |
run: | | |
set -x | |
export STATUS_URI="$( | |
curl --user 'system:System123' --max-time 10 --retry 5 --retry-delay 0 --retry-max-time 60 --connect-timeout 5 --silent \ | |
--request POST \ | |
--location \ | |
'http://localhost:8080/api/resourceTables/analytics' \ | |
| jq --raw-output '.response.relativeNotifierEndpoint' | |
)" | |
set +x | |
# Disable exiting on failure while parsing output | |
set +e | |
set +o pipefail | |
# Print status messages as they change | |
until [[ "$( curl --user 'system:System123' --max-time 10 --retry 5 --retry-delay 0 --retry-max-time 60 --connect-timeout 5 --silent "http://localhost:8080${STATUS_URI}" | jq --raw-output "sort_by(.time, .completed)|.[-1].completed" )" == "true" ]]; do | |
STATUS_CURRENT="$( curl --user 'system:System123' --max-time 10 --retry 5 --retry-delay 0 --retry-max-time 60 --connect-timeout 5 --silent "http://localhost:8080${STATUS_URI}" | jq "sort_by(.time, .completed)|.[-1]" )" | |
LINE_CURRENT="[$( jq --raw-output ".level" <<<"$STATUS_CURRENT" )] $( jq --raw-output ".time" <<<"$STATUS_CURRENT" ) $( jq --raw-output ".message" <<<"$STATUS_CURRENT" ) (Completed: $( jq --raw-output ".completed" <<<"$STATUS_CURRENT" ))" | |
if [[ "${LINE_PREV:-}" != "$LINE_CURRENT" ]]; then | |
echo "$LINE_CURRENT" | |
fi | |
LINE_PREV="$LINE_CURRENT" | |
sleep 3 | |
done | |
# Print final status message | |
STATUS_LATEST="$( curl --user 'system:System123' --max-time 10 --retry 5 --retry-delay 0 --retry-max-time 60 --connect-timeout 5 --silent "http://localhost:8080${STATUS_URI}" | jq "sort_by(.time, .completed)|.[-1]" )" | |
LINE_LATEST="[$( jq --raw-output ".level" <<<"$STATUS_LATEST" )] $( jq --raw-output ".time" <<<"$STATUS_LATEST" ) $( jq --raw-output ".message" <<<"$STATUS_LATEST" ) (Completed: $( jq --raw-output ".completed" <<<"$STATUS_LATEST" ))" | |
if [[ "${LINE_PREV:-}" != "$LINE_LATEST" ]]; then | |
echo "$LINE_LATEST" | |
fi | |
########################################################################## | |
# - name: Install NodeJS | |
# uses: actions/setup-node@56337c425554a6be30cdef71bf441f15be286854 | |
# with: | |
# node-version: '14' # NOTE: A dependency in dhis2/e2e-tests will not run in v16 or higher | |
# check-latest: true | |
# - name: Install Java # For Selenium | |
# uses: actions/setup-java@860f60056505705214d223b91ed7a30f173f6142 | |
# with: | |
# distribution: 'adopt' | |
# java-version: '11' | |
# - name: Install latest google-chrome-stable | |
# run: | | |
# set -x | |
# echo "deb [arch=$(dpkg --print-architecture)] http://dl.google.com/linux/chrome/deb/ stable main" | sudo tee /etc/apt/sources.list.d/google-chrome.list >/dev/null | |
# curl --silent https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/google.gpg >/dev/null | |
# sudo apt-get update | |
# if ! dpkg-query -W google-chrome-stable ; then | |
# sudo apt-get install -y --no-install-recommends google-chrome-stable | |
# else | |
# sudo apt-get install -y --only-upgrade google-chrome-stable | |
# fi | |
# - name: Checkout dhis2/e2e-tests to current directory | |
# uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | |
# with: | |
# repository: dhis2/e2e-tests | |
# ref: ${{ steps.versions_helper.outputs.e2e_remote_ref }} # "master" for dev, "${{ matrix.dhis2_version }}-rc" for releases; see "versions_helper" for logic | |
# fetch-depth: ${{ steps.versions_helper.outputs.e2e_remote_depth }} # default is "1", "0" for certain versions; see "versions_helper" for logic | |
# - name: Install dependencies for dhis2/e2e-tests | |
# run: | | |
# set -x | |
# npm install --legacy-peer-deps | |
# - name: Fix tests for 2.36.0 through 2.36.2 | |
# if: | | |
# matrix.dhis2_version == '2.36.0' || | |
# matrix.dhis2_version == '2.36.1' || | |
# matrix.dhis2_version == '2.36.2' | |
# run: | | |
# set -x | |
# git show 2e090dd85936d8e95b5e5ed43ed1ceea7094888a | sed --regexp-extended --expression='s,([ab]/)(step_definitions/),\1tests/\2,g' | git apply --reverse | |
# - name: Add headless Chrome options to wdio | |
# run: | | |
# set -x | |
# if [[ -f ./tests/config/wdio.local.conf.js ]]; then | |
# WDIO_CONFIG_PATH="./tests/config/wdio.local.conf.js" | |
# else | |
# WDIO_CONFIG_PATH="./wdio.conf.js" | |
# fi | |
# sed \ | |
# --regexp-extended \ | |
# --expression="/\s*--disable-web-security/ { s/^(\s*)/\1'--headless','--disable-gpu','--window-size=2048,1536','--ignore-certificate-errors','--disable-extensions','--no-sandbox','--disable-dev-shm-usage',\n\1/ }" \ | |
# --in-place \ | |
# "$WDIO_CONFIG_PATH" | |
# - name: Cucumber tests # does NOT require analytics to have been generated | |
# if: | # Tests fail on earlier versions for similar reasons as newer Mocha tests | |
# matrix.dhis2_version != '2.35.0' && | |
# matrix.dhis2_version != '2.35.1' && | |
# matrix.dhis2_version != '2.35.2' && | |
# matrix.dhis2_version != '2.35.3' && | |
# matrix.dhis2_version != '2.35.4' && | |
# matrix.dhis2_version != '2.35.5' && | |
# matrix.dhis2_version != '2.36.0' | |
# uses: nick-fields/retry@e88a9994b039653512d697de1bce46b00bfe11b5 | |
# with: | |
# timeout_minutes: 5 | |
# max_attempts: 3 | |
# warning_on_retry: false | |
# continue_on_error: ${{ endsWith(matrix.dhis2_version, 'dev') }} # don't block the remaining actions if it fails on dev versions | |
# command: | | |
# set -x | |
# npx wdio ./tests/config/wdio.cucumber.conf.js | |
# env: | |
# BASE_URL: http://localhost:8080/ | |
# DEBUG: '1' # Do not run in parallel; there can be more failures in GHA without this due to limited resources | |
########################################################################## | |
- name: Login to GitHub Container Registry | |
if: ${{ (github.ref == 'refs/heads/main') && (github.event_name != 'pull_request') && !env.ACT }} | |
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Copy image from local registry and push to public registry | |
if: ${{ (github.ref == 'refs/heads/main') && (github.event_name != 'pull_request') && !env.ACT }} | |
uses: akhilerm/tag-push-action@85bf542f43f5f2060ef76262a67ee3607cb6db37 | |
with: | |
src: ${{ fromJSON(steps.image_build.outputs.metadata)['image.name'] }} | |
dst: ${{ steps.image_meta.outputs.tags }} | |
########################################################################## | |
# - name: Upload npm logs | |
# if: always() | |
# uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce | |
# with: | |
# name: ${{ matrix.dhis2_version }}_npm | |
# path: /home/runner/.npm/_logs/ | |
# retention-days: 8 | |
# if-no-files-found: ignore | |
# - name: Upload wdio logs | |
# if: always() | |
# uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce | |
# with: | |
# name: ${{ matrix.dhis2_version }}_wdio | |
# path: output/ | |
# retention-days: 8 | |
# if-no-files-found: ignore | |
# # Archive files before uploading as an artifact because of the following warning without doing so: | |
# # "There are over 10,000 files in this artifact, consider creating an archive before upload to improve the upload performance." | |
# - name: Archive allure results | |
# if: always() | |
# run: | | |
# if [[ -d reports/allure-results ]] ; then | |
# cd reports/ | |
# zip -q -r allure-results.zip allure-results | |
# fi | |
# - name: Upload allure results | |
# if: always() | |
# uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce | |
# with: | |
# name: ${{ matrix.dhis2_version }}_allure | |
# path: reports/allure-results.zip | |
# retention-days: 8 | |
# if-no-files-found: ignore | |
check: | |
name: Check if required jobs passed # this job name is to be used as the single required status check in branch protection | |
if: success() | |
needs: build | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 3 | |
steps: | |
# See https://github.com/re-actors/alls-green/blob/3a2de129/README.md for why this is here | |
- name: Decide whether the needed jobs succeeded or failed | |
uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe | |
with: | |
jobs: ${{ toJSON(needs) }} |