Skip to content

chore: spin up local instances #3201

chore: spin up local instances

chore: spin up local instances #3201

name: 'dhis2: verify (app)'
on:
pull_request:
types: ['opened', 'edited', 'reopened', 'synchronize']
push:
branches:
- 'master'
- 'dev'
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
env:
GIT_AUTHOR_NAME: '@dhis2-bot'
GIT_AUTHOR_EMAIL: '[email protected]'
GIT_COMMITTER_NAME: '@dhis2-bot'
GIT_COMMITTER_EMAIL: '[email protected]'
GH_TOKEN: ${{secrets.DHIS2_BOT_GITHUB_TOKEN}}
D2_VERBOSE: true
CI: true
jobs:
build-and-verify:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Install
run: yarn install --frozen-lockfile
- name: Build
run: yarn d2-app-scripts build
- name: Lint
run: yarn d2-style check
- name: Test
run: yarn d2-app-scripts test
- name: Upload artefact
uses: actions/upload-artifact@v3
with:
name: app-build
path: |
**/build
!**/node_modules
retention-days: 1
retrieve-supported-versions:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Retrieve supported versions
id: supported-versions
uses: ./.github/actions/supported-versions
with:
broken-versions: '2.39.2.1'
outputs:
versions: ${{ steps.supported-versions.outputs.versions }}
cache-analytics-db:
runs-on: ubuntu-latest
needs: [retrieve-supported-versions]
if: ${{ !github.event.push.repository.fork && (github.event.pull_request.draft != 'true' || github.action == 'workflow_dispatch') }}
strategy:
fail-fast: false
matrix:
versions: ${{ fromJSON(needs.retrieve-supported-versions.outputs.versions) }}
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Compute DHIS2 Core version parameters
id: instance-version-params
uses: ./.github/actions/instance-version-params
with:
version: ${{ matrix.versions }}
# Credit: https://github.com/actions/toolkit/issues/995
- name: Check if DB cache exists
id: check-if-db-cache-exists
run: |
gh extension install actions/gh-actions-cache
KEY=${{ steps.instance-version-params.outputs.dhis2-db-cache-key }}
CACHE_HIT=$(gh actions-cache list --key $KEY | grep -q $KEY && echo 'true' || echo 'false')
if [ "$CACHE_HIT" == 'true' ]
then
echo "::notice::Cached database dump found, skipping subsequent steps"
else
echo "::notice::No cached database dump found, proceed to generate them in the next steps"
fi
echo "cache-hit=$CACHE_HIT" >> $GITHUB_OUTPUT
- name: Spin up DHIS2 Core Docker Image
if: ${{ steps.check-if-db-cache-exists.outputs.cache-hit != 'true' }}
run: |
docker compose up -d
sleep 5s
curl --head -X GET --retry-max-time 300 --retry-connrefused --retry-delay 1 http://127.0.0.1:8080
docker ps
docker compose logs web
env:
DHIS2_IMAGE: ${{ steps.instance-version-params.outputs.dhis2-docker-hub-image-tag }}
DHIS2_DB_DUMP_URL: ${{ steps.instance-version-params.outputs.dhis2-db-dump-url }}
- name: Generate analytics tables
if: ${{ steps.check-if-db-cache-exists.outputs.cache-hit != 'true' }}
uses: ./.github/actions/generate-analytics-tables
with:
dhis2-username: ${{ secrets.CYPRESS_DHIS2_USERNAME }}
dhis2-password: ${{ secrets.CYPRESS_DHIS2_PASSWORD }}
dhis2-api-version: ${{ steps.instance-version-params.outputs.dhis2-api-version }}
- name: Create database dump
if: ${{ steps.check-if-db-cache-exists.outputs.cache-hit != 'true' }}
# Backing up to a `.pgc` file would be preferable because this is faster to restore
# But doing so seems to result in missing data. In any case the e2e suite is no longer passing
# run: |
# sudo mkdir -p opt/dump
# sudo chown -R $USER:$(id -g) opt/dump && sudo chmod -R ugo+rwx opt/dump
# sudo ls -laR opt/dump
# sudo pg_dump -Fc -Z 9 --no-owner --no-privileges 'postgresql://dhis:[email protected]:5432/dhis' >opt/dump/dump.pgc
run: |
sudo mkdir -p opt/dump
sudo chown -R $USER:$(id -g) opt/dump && sudo chmod -R ugo+rwx opt/dump
sudo ls -laR opt/dump
sudo pg_dump 'postgresql://dhis:[email protected]:5432/dhis' | gzip >opt/dump/dump.sql.gz
- name: Save DB dump in GitHub Actions Cache
if: ${{ steps.check-if-db-cache-exists.outputs.cache-hit != 'true' }}
uses: actions/cache/save@v3
id: cached-db-dump
with:
# path: opt/dump/dump.pgc
path: opt/dump/dump.sql.gz
key: ${{ steps.instance-version-params.outputs.dhis2-db-cache-key }}
integration:
runs-on: ubuntu-latest
if: ${{ !github.event.push.repository.fork && (github.event.pull_request.draft != 'true' || github.action == 'workflow_dispatch') }}
needs:
[retrieve-supported-versions, build-and-verify, cache-analytics-db]
strategy:
fail-fast: false
matrix:
versions: ${{ fromJSON(needs.retrieve-supported-versions.outputs.versions) }}
containers: [1, 2]
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Compute DHIS2 Core version parameters
id: instance-version-params
uses: ./.github/actions/instance-version-params
with:
version: ${{ matrix.versions }}
- name: Restore DB dump
uses: actions/cache/restore@v3
id: cached-db-dump
with:
# path: opt/dump/dump.pgc
path: opt/dump/dump.sql.gz
key: ${{ steps.instance-version-params.outputs.dhis2-db-cache-key }}
- name: End-to-End tests
uses: cypress-io/github-action@v5
with:
start: docker compose up -d, yarn start
wait-on: 'http://localhost:8080/dhis-web-commons/security/login.action, http://localhost:3000'
wait-on-timeout: 1200
record: true
parallel: true
browser: chrome
group: e2e-chrome-parallel-${{ matrix.versions }}
env:
BROWSER: none
CI: true
CYPRESS_dhis2BaseUrl: http://localhost:8080
CYPRESS_dhis2InstanceVersion: ${{matrix.versions}}
CYPRESS_dhis2Password: ${{ secrets.CYPRESS_DHIS2_PASSWORD }}
CYPRESS_dhis2Username: ${{ secrets.CYPRESS_DHIS2_USERNAME }}
CYPRESS_networkMode: live
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
DHIS2_IMAGE: ${{ steps.instance-version-params.outputs.dhis2-docker-hub-image-tag }}
DHIS2_DB_DUMP_URL: ${{ steps.instance-version-params.outputs.dhis2-db-dump-url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# DEBUG: 'cypress:*'
# This can be removed once Cypress Cloud starts working again
- name: Save videos as artifact
uses: actions/upload-artifact@v2
if: always()
with:
name: cypress-videos
path: cypress/videos
release:
runs-on: ubuntu-latest
needs: integration
if: |
!github.event.push.repository.fork &&
github.actor != 'dependabot[bot]' &&
github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.DHIS2_BOT_GITHUB_TOKEN }}
- uses: actions/setup-node@v3
with:
node-version: 18.x
- uses: actions/download-artifact@v3
with:
name: app-build
- name: Install
run: yarn install --frozen-lockfile
- uses: dhis2/action-semantic-release@master
with:
publish-apphub: true
publish-github: true
github-token: ${{ secrets.DHIS2_BOT_GITHUB_TOKEN }}
apphub-token: ${{ secrets.DHIS2_BOT_APPHUB_TOKEN }}
- uses: dhis2/deploy-build@master
with:
build-dir: build/app
github-token: ${{ secrets.DHIS2_BOT_GITHUB_TOKEN }}
report-release-failure:
runs-on: ubuntu-latest
needs: release
if: |
failure() &&
!cancelled() &&
github.ref == 'refs/heads/master' &&
contains(github.event.head_commit.message, 'chore(release)')
steps:
- name: Checkout code
uses: actions/checkout@master
- name: Extract version
id: extract_version
uses: Saionaro/[email protected]
- name: Send failure message to analytics-internal-bot slack channel
id: slack
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
payload: |
{
"text": ":small_red_triangle_down: :line-listing-app: Line Listing release <https://github.com/dhis2/line-listing-app/actions/workflows/dhis2-verify-app.yml?query=branch%3Amaster+is%3Afailure|failed>",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":small_red_triangle_down: :line-listing-app: Line Listing release <https://github.com/dhis2/line-listing-app/actions/workflows/dhis2-verify-app.yml?query=branch%3Amaster+is%3Afailure|failed>"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
report-release-success:
runs-on: ubuntu-latest
needs: release
if: |
success() &&
!cancelled() &&
github.ref == 'refs/heads/master' &&
contains(github.event.head_commit.message, 'chore(release)')
steps:
- name: Checkout code
uses: actions/checkout@master
- name: Extract version
id: extract_version
uses: Saionaro/[email protected]
- name: Send success message to analytics-internal-bot slack channel
id: slack
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
payload: |
{
"text": ":large_green_circle: :line-listing-app: :tada: Line Listing release succeeded for version: ${{ steps.extract_version.outputs.version }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":large_green_circle: :line-listing-app: :tada: Line Listing version ${{ steps.extract_version.outputs.version }} released <https://github.com/dhis2/line-listing-app/actions/workflows/dhis2-verify-app.yml?query=branch%3Amaster+is%3Asuccess|successfully>"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}