Skip to content

Commit

Permalink
feat: prepare maps-app for continuous release on the app hub (#2572)
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

* Set to breaking change to trigger version push to 100.0.0
* Add cypress tags to allow testing features that are toggled on for versions
* Align the PR workflow with DV and LL
* Use dhis2/action-semantic-release@master action, same as DV and LL
* Add the nightly workflow
* Add the preview pr workflow
  • Loading branch information
jenniferarnesen authored Apr 21, 2023
1 parent ec245ec commit aa56d59
Show file tree
Hide file tree
Showing 8 changed files with 1,396 additions and 237 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/dhis2-preview-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: 'dhis2: pr preview'

# Requirements:
#
# - Org secrets:
# DHIS2_BOT_NETLIFY_TOKEN
# DHIS2_BOT_GITHUB_TOKEN
# - Repo secrets:
# NETLIFY_SITE_ID
# - Customize the 'jobs.build.steps.netlify-deploy.publish-dir' property

on: pull_request

concurrency:
group: ${{ github.workflow}}-${{ github.ref }}
cancel-in-progress: true

jobs:
preview:
runs-on: ubuntu-latest
if: "!github.event.push.repository.fork && github.actor != 'dependabot[bot]'"
steps:
- uses: actions/checkout@v3
- 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 --standalone

- name: Deploy
id: netlify-deploy
uses: nwtgck/[email protected]
timeout-minutes: 1
with:
github-token: ${{ secrets.DHIS2_BOT_GITHUB_TOKEN }}
github-deployment-environment: 'netlify'
github-deployment-description: 'PR Preview on Netlify'
deploy-message: ${{ github.event.pull_request.title }}
enable-pull-request-comment: true
enable-commit-comment: true
enable-commit-status: true
alias: pr-${{ github.event.number }}
# customize according to project needs
publish-dir: 'build/app'
env:
# org secret
NETLIFY_AUTH_TOKEN: ${{ secrets.DHIS2_BOT_NETLIFY_TOKEN }}
# repo secret
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
175 changes: 60 additions & 115 deletions .github/workflows/dhis2-verify-app.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
name: 'dhis2: verify (app)'

on:
pull_request:
types: ['opened', 'edited', 'reopened', 'synchronize']
push:
branches:
- 'master'
- 'dev'

env:
GIT_AUTHOR_NAME: '@dhis2-bot'
Expand All @@ -13,46 +17,21 @@ env:
CI: true

jobs:
install:
build:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18.x

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: '**/node_modules'
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}

- name: Install
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile

build:
runs-on: ubuntu-latest
needs: install
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: 18.x

- uses: actions/cache@v2
id: yarn-cache
with:
path: '**/node_modules'
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}

- name: Build
run: yarn build
run: yarn d2-app-scripts build

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
with:
name: app-build
path: |
Expand All @@ -62,130 +41,96 @@ jobs:

lint:
runs-on: ubuntu-latest
needs: install
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18.x

- uses: actions/cache@v2
id: yarn-cache
with:
path: '**/node_modules'
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
- name: Install
run: yarn install --frozen-lockfile

- name: Generate translations
run: yarn d2-app-scripts i18n generate

- name: Lint
run: yarn lint
run: yarn d2-style check

test:
runs-on: ubuntu-latest
needs: install
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18.x

- uses: actions/cache@v2
id: yarn-cache
with:
path: '**/node_modules'
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
- name: Install
run: yarn install --frozen-lockfile

- name: Generate translations
run: yarn d2-app-scripts i18n generate

- name: Test
run: yarn test
run: yarn d2-app-scripts test

e2e:
needs: install
runs-on: ubuntu-latest
container:
image: cypress/browsers:node16.17.0-chrome106
options: --user 1001
call-workflow-e2e-prod:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
needs: [build, lint, test]
uses: dhis2/data-visualizer-app/.github/workflows/e2e-prod.yml@dev
secrets:
baseurl: ${{ secrets.CYPRESS_DHIS2_BASE_URL_DEV }}
username: ${{ secrets.CYPRESS_DHIS2_USERNAME }}
password: ${{ secrets.CYPRESS_DHIS2_PASSWORD }}
recordkey: ${{ secrets.CYPRESS_RECORD_KEY }}

strategy:
matrix:
containers: [1, 2, 3, 4]

release:
runs-on: ubuntu-latest
needs: call-workflow-e2e-prod
if: |
!github.event.push.repository.fork &&
github.actor != 'dependabot[bot]' &&
github.ref == 'refs/heads/master'
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
token: ${{ secrets.DHIS2_BOT_GITHUB_TOKEN }}

- uses: actions/setup-node@v3
with:
node-version: 18.x

- uses: actions/cache@v2
id: yarn-cache
- uses: actions/download-artifact@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}

- name: Install Cypress binary
run: yarn cypress install

- name: End-to-End tests
uses: cypress-io/github-action@v2
with:
start: yarn d2-app-scripts start
wait-on: 'http://localhost:3000'
wait-on-timeout: 300
record: true
parallel: true
browser: chrome
group: 'e2e'
tag: ${{ github.event_name }}
env:
CI: true
BROWSER: none
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }}
CYPRESS_dhis2BaseUrl: ${{ secrets.CYPRESS_DHIS2_BASE_URL_DEV }}
CYPRESS_dhis2Username: ${{ secrets.CYPRESS_DHIS2_USERNAME }}
CYPRESS_dhis2Password: ${{ secrets.CYPRESS_DHIS2_PASSWORD }}
CYPRESS_networkMode: 'live'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish:
runs-on: ubuntu-latest
needs: [build, lint, test]
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v2
with:
token: ${{env.GH_TOKEN}}
name: app-build

- uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Install
run: yarn install --frozen-lockfile

- uses: actions/download-artifact@v2
- uses: dhis2/action-semantic-release@master
with:
name: app-build
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: ${{ env.GH_TOKEN }}
github-token: ${{ secrets.DHIS2_BOT_GITHUB_TOKEN }}

release:
report-release-failure:
runs-on: ubuntu-latest
needs: [publish]
if: "github.event_name == 'push' && !contains(github.event.head_commit.message, '[skip ci]')"
needs: release
if: |
failure() &&
!cancelled() &&
github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v2
with:
token: ${{env.GH_TOKEN}}

- uses: actions/setup-node@v1
- name: Send failure message to analytics-internal-bot slack channel
id: slack
uses: slackapi/[email protected]
with:
node-version: 14.x

- name: Publish release to GitHub
run: npx @dhis2/cli-utils release
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
slack-message: ':small_red_triangle_down: Maps-app release <https://github.com/dhis2/maps-app/actions/workflows/dhis2-verify-app.yml?query=branch%3Amaster+is%3Afailure>'
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
41 changes: 41 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: 'dhis2: nightly'

# This workflow runs the e2e tests on the default branch against dev at 4:20am M-F

on:
schedule:
- cron: '20 4 * * 1-5'

concurrency:
group: ${{ github.workflow}}-${{ github.ref }}
cancel-in-progress: true

defaults:
run:
shell: bash

jobs:
call-workflow-e2e-dev:
if: github.ref == 'refs/heads/dev'
uses: dhis2/data-visualizer-app/.github/workflows/e2e-dev.yml@dev
secrets:
baseurl: ${{ secrets.CYPRESS_DHIS2_BASE_URL_DEV }}
username: ${{ secrets.CYPRESS_DHIS2_USERNAME }}
password: ${{ secrets.CYPRESS_DHIS2_PASSWORD }}
recordkey: ${{ secrets.CYPRESS_RECORD_KEY }}

send-slack-message:
runs-on: ubuntu-latest
needs: call-workflow-e2e-dev
if: |
failure() &&
!cancelled()
steps:
- name: Send failure message to analytics-internal-kfmt slack channel
id: slack
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
slack-message: ':x: Maps-app e2e nightly run <https://cloud.cypress.io/projects/r5jduj/runs?branches=[{"label":"dev","suggested":false,"value":"dev"}]|failed>'
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
19 changes: 18 additions & 1 deletion cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const { existsSync, readdirSync, lstatSync } = require('fs')
const path = require('path')
const { chromeAllowXSiteCookies } = require('@dhis2/cypress-plugins')
const { tagify } = require('cypress-tags')
const fsExtra = require('fs-extra')
const { getExcludedTags } = require('../support/getExcludedTags.js')

const downloadsDirPath = 'cypress/downloads'

Expand Down Expand Up @@ -33,8 +35,23 @@ const emptyDownloadsFolder = () => {
return null
}

module.exports = (on) => {
module.exports = (on, config) => {
chromeAllowXSiteCookies(on)

if (!config.env.dhis2InstanceVersion) {
throw new Error(
'dhis2InstanceVersion is missing. Check the README for more information.'
)
}

const excludedTags = getExcludedTags(config.env.dhis2InstanceVersion)

console.log('instanceVersion', config.env.dhis2InstanceVersion)
console.log('tags to exclude from testing', excludedTags)

config.env.CYPRESS_EXCLUDE_TAGS = excludedTags.join(',')

on('file:preprocessor', tagify(config))
on('task', {
getLastDownloadFilePath,
emptyDownloadsFolder,
Expand Down
Loading

0 comments on commit aa56d59

Please sign in to comment.