Skip to content

MAQS Java Pipeline #1019

MAQS Java Pipeline

MAQS Java Pipeline #1019

Workflow file for this run

name: MAQS Java Pipeline
on:
schedule:
- cron: "13 23 * * *"
push:
branches:
- main
pull_request:
branches: [ main ]
workflow_dispatch:
inputs:
override:
description: 'Version Number'
required: true
default: '0.0.0'
jobs:
waitOld:
name: Wait For Older Runs To Complete
runs-on: ubuntu-latest
steps:
- name: Wait
id: wait
shell: pwsh
run: |
$runID = ${{ github.run_id }}
$endPoint = "https://api.github.com/repos/${{github.repository}}/actions/runs"
$timeout = New-TimeSpan -Minutes 60
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
do {
$result = Invoke-RestMethod -Uri $endPoint
$builds = $result.workflow_runs | Where-Object {$_.name -eq "Build" -and ($_.status -eq "in_progress" -or $_.status -eq "queued") -and $_.id -lt $runID}
# Check if there were any older build runs still going, if not we waited long enough
if (!$builds)
{
Write-Host "Are now top of the run queue"
return
}
Start-Sleep -s 60
Write-Host "Waited so far $($stopwatch.elapsed)"
} while ($stopwatch.elapsed -lt $timeout)
Write-Host "Waited more than an hour for earlier runs to complete, continuing action pipeline"
draftRelease:
name: Draft release
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5.21.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
getVersion:
name: Get package version
runs-on: ubuntu-latest
if: ${{ always() }}
outputs:
buildNumber: ${{ steps.ver.outputs.BUILD_NUMBER }}
steps:
- name: GetVersion
id: ver
shell: pwsh
run: |
if ("${{github.event.inputs.override}}")
{
Write-Host "Using manually entered override version"
$version = "${{ github.event.inputs.override}}"
}
else
{
$header = @{Authorization = 'Bearer ${{ secrets.GITHUB_TOKEN }}' }
$endPoint = "https://api.github.com/repos/${{github.repository}}/releases"
$info = Invoke-RestMethod -Uri $endPoint -Headers $header
$version = $info.name[0].Trim("v")
}
Write-Host "::set-output name=BUILD_NUMBER::$($version)"
install-modules:
name: Pre-compile packages
runs-on: ubuntu-latest
outputs:
buildNumber: ${{ steps.ver.outputs.BUILD_NUMBER }}
steps:
- uses: actions/checkout@v3
- name: Preload packages into cache
id: builder
uses: ./.github/workflows/preinstall-action
with:
bt-param: '-fae -B -e -T 1C -Psonar'
version: ${{ github.sha }}
test-modules:
name: Test Modules
needs: [ waitOld, install-modules ]
runs-on: ubuntu-latest
env:
SAUCE: ${{secrets.SAUCE}}
strategy:
fail-fast: false
matrix:
module-name: [ maqs-utilities, maqs-base, maqs-appium, maqs-selenium, maqs-webservices, maqs-cucumber, maqs-accessibility, maqs-database, maqs-playwright ]
steps:
- name: Check if tests can be run
if: matrix.module-name == 'maqs-appium' && github.actor == 'dependabot[bot]'
run: |
echo Cannot run Appium tests when build was triggered by dependabot
exit 1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
if: matrix.module-name == 'maqs-playwright'
with:
node-version: '14.x'
- name: Install Playwright
if: matrix.module-name == 'maqs-playwright'
run: npx playwright install --with-deps
- name: Build and Start Unit Tests
id: builder
uses: ./.github/workflows/buildtest-action
with:
module-name: ${{matrix.module-name}}
bt-param: '-fae -B -e -Dtesting=solo -T 1C'
version: ${{ github.sha }}
- name: Test Reporting
if: always() && github.actor != 'dependabot[bot]'
id: test-report
uses: phoenix-actions/test-reporting@v10
with:
name: ${{matrix.module-name}} Test Results
path: '**/junitreports/TEST-**.xml'
reporter: 'java-junit'
list-tests: 'failed'
list-suites: 'failed'
fail-on-error: 'false'
- uses: actions/upload-artifact@v3
if: always()
name: "Upload test artifact"
with:
name: ${{matrix.module-name}}-results
path: |
${{matrix.module-name}}/target/**/*.xml
${{matrix.module-name}}/target/logs
${{matrix.module-name}}/target/**/*.exec
${{matrix.module-name}}/target/**/*.jar
sonarcloud:
name: SonarCloud Analysis
runs-on: ubuntu-latest
needs: [test-modules, getVersion]
env:
SONAR_ORG: "cognizantopensource"
SONAR_PROJECT: "CognizantOpenSource_maqs-java"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{secrets.SONAR_TOKEN}}
VERSION: ${{ needs.getVersion.outputs.buildNumber }}
steps:
- name: Checkout Source
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/download-artifact@v3
with:
path: ${{github.workspace}}/artifacts/
- name: Set up JDK 11
uses: actions/setup-java@v3.6.0
with:
distribution: zulu
java-version: 11
cache: maven
- name: Create settings file
uses: InstaCode/maven-settings-xml-action@v9
with:
profiles: '[{ "id": "sonar", "properties": { "sonar.organization":"${{env.SONAR_ORG}}", "sonar.host.url":"https://sonarcloud.io", "sonar.login": "${{secrets.SONAR_TOKEN}}" }}]'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Restore Local Maven Cache
uses: actions/cache@v3.0.11
with:
path: ~/.m2
key: ${{ runner.os }}-maven-${{github.sha}}.${{github.run_number}}
restore-keys: |
${{ runner.os }}-maven-${{github.sha}}
- name: Run SonarCloud Analysis
shell: bash
run: mvn -B -e -fae -Drevision=${{env.VERSION}} -Psonar package sonar:sonar -Dsonar.projectKey=${{env.SONAR_PROJECT}} -Dsonar.projectName=maqs-java -Dsonar.coverage.jacoco.xmlReportPaths=$(find "$(pwd)" -path '*jacoco.xml' | sed 's/.*/&/' | tr '\n' ',')
working-directory: ${{github.workspace}}
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
checkstyle:
name: Checkstyle Run
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3.6.0
with:
distribution: zulu
java-version: 11
cache: maven
- name: Restore Local Maven Cache
uses: actions/cache@v3.0.11
with:
path: ~/.m2
key: ${{runner.os}}-m2
- name: Run Checkstyle
run: mvn -B validate --file pom.xml -e -fae
labels:
name: Pull Request Labels
if: github.actor != 'dependabot[bot]'
runs-on: ubuntu-latest
steps:
- name: Label Pull Request
uses: actions/labeler@v4
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
publish:
name: Publish Packages
runs-on: ubuntu-latest
needs: [sonarcloud, checkstyle, getVersion]
environment: GitHub
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.event_name != 'schedule'
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3.6.0
with:
distribution: zulu
java-version: 11
cache: maven
overwrite-settings: true
server-id: github
# server-username: ${{secrets.DEPLOY_USER_NAME}}
server-password: ${{secrets.DEPLOY_PACKAGE}}
- name: Restore Local Maven Cache
uses: actions/cache@v3.0.11
with:
path: ~/.m2
key: ${{runner.os}}-m2
- name: Deploy Release v${{ needs.getVersion.outputs.buildNumber }} to GitHub
run: mvn -Drevision=${{ needs.getVersion.outputs.buildNumber }} deploy -P github,deploy
- name: Publish GitHub release v${{ needs.getVersion.outputs.buildNumber }}
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const result = await github.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo
})
var id = "NA"
var data = result.data
for(var key in data){
if(data[key].tag_name == "v${{ needs.getVersion.outputs.buildNumber }}" && data[key].draft == true)
{
github.repos.updateRelease({
release_id: data[key].id,
"draft": false,
owner: context.repo.owner,
repo: context.repo.repo });
return;
}
}
console.error("Failed to find related draft release");