Wiki Spaces
Documentation
Projects
Resources
Get Help from Others
Q&A: Ask OpenMRS
Discussion: OpenMRS Talk
Real-Time: IRC Chat | Slack
The default OpenMRS-recommended GitHub Actions definition for OpenMRS backend modules should look like the below. This is designed to replicate the build process used on Travis-CI, first downloading all requirements and compiling the module before running any tests. Tests are then run afterwards. Tweaks might need to be made to accomodate specific modules build processes, but this should work for Maven-based builds.
# this build is designed to replicate the Travis CI workflow name: Build with Maven on: push: branches: [ master ] pull_request: branches: [ master ] workflow_dispatch: jobs: build: strategy: matrix: platform: [ ubuntu-latest ] java-version: [ 8 ] runs-on: ${{ matrix.platform }} env: PLATFORM: ${{ matrix.platform }} JAVA_VERSION: ${{ matrix.java-version }} steps: - uses: actions/checkout@v2 - name: Set up JDK uses: actions/setup-java@v1 with: java-version: ${{ matrix.java-version }} - name: Cache local Maven repository uses: actions/cache@v2 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} restore-keys: | ${{ runner.os }}-maven- - name: Install dependencies run: mvn clean install -DskipTests=true -Dmaven.javadoc.skip=true --batch-mode --show-version --file pom.xml - name: Build with Maven run: mvn test --batch-mode --file pom.xml
For OpenMRS ESM modules, we use the following.
name: Node.js CI on: push: branches: [master] pull_request: branches: [master] release: types: - created env: ESM_NAME: "@openmrs/esm-template-app" JS_NAME: "openmrs-esm-template-app.js" jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Use Node.js uses: actions/setup-node@v1 with: node-version: "14.x" - run: npm install - run: npm run lint - run: npm run coverage - run: npm run typescript - run: npm run build --if-present - name: Upload Artifacts uses: actions/upload-artifact@v2 with: name: dist path: | dist pre_release: runs-on: ubuntu-latest needs: build if: ${{ github.event_name == 'push' }} steps: - uses: actions/checkout@v2 - name: Download Artifacts uses: actions/download-artifact@v2 - name: Use Node.js uses: actions/setup-node@v1 with: node-version: "14.x" registry-url: "https://registry.npmjs.org" - run: npm install - run: sed -i -e "s/\(\"version\":\\s\+\"\([0-9]\+\.\?\)\+\)/\1-pre.${{ github.run_number }}/" 'package.json' - run: npm publish --access public --tag next env: NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} release: runs-on: ubuntu-latest needs: build if: ${{ github.event_name == 'release' }} steps: - uses: actions/checkout@v2 - name: Download Artifacts uses: actions/download-artifact@v2 - name: Use Node.js uses: actions/setup-node@v1 with: node-version: "14.x" registry-url: 'https://registry.npmjs.org' - run: npm install - run: npm publish --access public env: NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
For OpenMRS OWAs, we use the following to build on each PR:
# this build is designed to replicate the Travis CI workflow name: Test Pull Request on: pull_request: branches: [ 'master' ] jobs: build: runs-on: ubuntu-latest strategy: matrix: node-version: [ 14.x ] steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - run: npm ci - run: npm run build --if-present - run: npm test
And this to build on each request, which also deploys the SNAPSHOT OWA to our Maven server:
name: Build Latest on: push: branches: [ 'master' ] jobs: build: runs-on: ubuntu-latest strategy: matrix: node-version: [ 14.x ] steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - run: npm ci - run: npm run build --if-present - run: npm test - name: Set up JDK 1.8 and Maven settings file uses: actions/setup-java@v1 with: java-version: 1.8 server-id: openmrs-repo-owa server-username: MAVEN_REPO_USERNAME server-password: MAVEN_REPO_PASSWORD - name: Extract the name of the built artifact run: echo "ARTIFACT_NAME=`echo $(find . -maxdepth 1 -name "labworkflow-*.zip" -printf '%P')`" >> $GITHUB_ENV - name: Deploy to Maven if it is a SNAPSHOT run: mvn deploy:deploy-file -Pdeploy-snapshot if: contains(env.ARTIFACT_NAME, '-SNAPSHOT') env: MAVEN_REPO_USERNAME: ${{ secrets.MAVEN_REPO_USERNAME }} MAVEN_REPO_PASSWORD: ${{ secrets.MAVEN_REPO_API_KEY }}
Finally, we use this configuration for a release:
name: Deploy release on: release: types: [ published ] jobs: build: runs-on: ubuntu-latest strategy: matrix: node-version: [ 14.x ] steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - run: npm ci - run: npm run build --if-present - run: npm test - name: Set up JDK 1.8 and Maven settings file uses: actions/setup-java@v1 with: java-version: 1.8 server-id: openmrs-repo-owa server-username: MAVEN_REPO_USERNAME server-password: MAVEN_REPO_PASSWORD - name: Deploy to Maven run: mvn deploy:deploy-file -Pdeploy-release env: MAVEN_REPO_USERNAME: ${{ secrets.MAVEN_REPO_USERNAME }} MAVEN_REPO_PASSWORD: ${{ secrets.MAVEN_REPO_API_KEY }}
Note that the OWA release deployments will need likely need to be tweaked for every OWA.