OpenMAQS Java Pipeline #931
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: OpenMAQS 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/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
dependency-tree: | |
name: Maven Dependency Tree | |
if: github.event_name == 'push' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/[email protected] | |
with: | |
distribution: zulu | |
java-version: 17 | |
cache: maven | |
- name: Restore Local Maven Cache | |
uses: actions/[email protected] | |
with: | |
path: ~/.m2 | |
key: ${{runner.os}}-m2 | |
- name: Submit Dependency Snapshot | |
uses: advanced-security/maven-dependency-submission-action@v3 | |
getVersion: | |
name: Get package version | |
runs-on: ubuntu-latest | |
if: ${{ always() }} | |
outputs: | |
buildNumber: ${{ steps.ver.outputs.BUILD_NUMBER }} | |
tagName: ${{ steps.ver.outputs.TAG_NAME }} | |
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)" | |
# Write-Host "BUILD_NUMBER=$($version)" >> GITHUB_OUTPUT | |
install-modules: | |
name: Pre-compile packages | |
runs-on: ubuntu-latest | |
outputs: | |
buildNumber: ${{ steps.ver.outputs.BUILD_NUMBER }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Preload packages into cache | |
id: builder | |
uses: ./.github/actions/preinstall | |
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_HUB_URL: ${{secrets.SAUCE_HUB_URL}} | |
SAUCE: ${{secrets.SAUCE}} | |
strategy: | |
fail-fast: false | |
matrix: | |
module-name: [ openmaqs-utilities, openmaqs-base, openmaqs-appium, openmaqs-selenium, openmaqs-webservices, openmaqs-cucumber, openmaqs-accessibility, openmaqs-database, openmaqs-playwright ] | |
steps: | |
- name: Check if tests can be run | |
if: matrix.module-name == 'openmaqs-appium' && github.actor == 'dependabot[bot]' | |
run: | | |
echo Cannot run Appium tests when build was triggered by dependabot | |
exit 1 | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
if: matrix.module-name == 'openmaqs-playwright' | |
with: | |
node-version: '14.x' | |
- name: Install Playwright | |
if: matrix.module-name == 'openmaqs-playwright' | |
run: npx playwright install --with-deps | |
- name: Build and Start Unit Tests | |
id: builder | |
uses: ./.github/actions/buildtest | |
with: | |
module-name: ${{matrix.module-name}} | |
bt-param: '-fae -B -e -Dtesting=solo -T 1C' | |
version: ${{ github.sha }} | |
- name: Test Reporting | |
if: always() | |
id: test-report | |
uses: phoenix-actions/test-reporting@v12 | |
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: "openmaqs" | |
SONAR_PROJECT: "OpenMAQS_openmaqs-java" | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{secrets.SONAR_TOKEN}} | |
VERSION: ${{ needs.getVersion.outputs.buildNumber }} | |
steps: | |
- name: Checkout Source | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- uses: actions/download-artifact@v3 | |
with: | |
path: ${{github.workspace}}/artifacts/ | |
- name: Set up JDK 17 | |
uses: actions/[email protected] | |
with: | |
distribution: zulu | |
java-version: 17 | |
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": "${{env.SONAR_TOKEN}}" }}]' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Restore Local Maven Cache | |
uses: actions/[email protected] | |
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.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@v4 | |
- name: Set up JDK 17 | |
uses: actions/[email protected] | |
with: | |
distribution: zulu | |
java-version: 17 | |
cache: maven | |
- name: Restore Local Maven Cache | |
uses: actions/[email protected] | |
with: | |
path: ~/.m2 | |
key: ${{runner.os}}-m2 | |
- name: Run Checkstyle | |
run: mvn -B validate --file pom.xml -e -fae | |
labels: | |
name: Pull Request Labels | |
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: OSSRH | |
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.event_name != 'schedule' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 11 | |
uses: actions/[email protected] | |
with: | |
distribution: zulu | |
java-version: 11 | |
cache: maven | |
- name: Restore Local Maven Cache | |
uses: actions/[email protected] | |
with: | |
path: ~/.m2 | |
key: ${{runner.os}}-m2 | |
- name: Create settings file | |
uses: whelk-io/maven-settings-xml-action@v21 | |
with: | |
profiles: '[{"id": "gpg", "properties": { "gpg.keyname": "${{secrets.GPG_KEYNAME_ID}}", "gpg.passphrase": "${{secrets.GPG_PASSPHRASE}}" }}]' | |
servers: '[{"id": "ossrh", "username": "${{secrets.DEPLOY_PACKAGE_USERNAME}}", "password": "${{secrets.DEPLOY_PACKAGE_PASSWORD}}"}]' | |
active_profiles: > | |
[ "ossrh", "release", "gpg" ] | |
- name: Import GPG key | |
id: import_gpg | |
uses: crazy-max/[email protected] | |
with: | |
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} | |
passphrase: ${{ secrets.GPG_PASSPHRASE }} | |
- name: Deploy Release v${{ needs.getVersion.outputs.buildNumber }} to OSSRH | |
run: mvn -B -e -Drevision=${{ needs.getVersion.outputs.buildNumber }} deploy | |
- name: Publish GitHub release v${{ needs.getVersion.outputs.buildNumber }} | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const result = await github.action.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.action.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"); |