Skip to content

AJ-1095 - Fix Publish logic - Enable skipping publish on main branch #39

AJ-1095 - Fix Publish logic - Enable skipping publish on main branch

AJ-1095 - Fix Publish logic - Enable skipping publish on main branch #39

name: Build, Test and Publish
on:
workflow_dispatch:
inputs:
publish:
description: 'If true, run the tag and publish jobs'
required: true
type: boolean
default: false
push:
branches: [ main ]
paths-ignore:
- '*.md'
- 'settings.gradle' # Avoid running workflows on version bumps
pull_request:
branches: [ '**' ]
env:
RUN_PUBLISH: ${{ (github.ref == 'refs/heads/main' && github.event_name != 'workflow_dispatch') || (github.event_name == 'workflow_dispatch' && inputs.publish) }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: 'gradle'
- name: Build all projects without running tests
run: ./gradlew --build-cache build -x test
source-clear:
needs: [ build ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: 'gradle'
- name: SourceClear scan
env:
SRCCLR_API_TOKEN: ${{ secrets.SRCCLR_API_TOKEN }}
run: ./gradlew --build-cache srcclr
unit-tests-and-sonarqube:
needs: [ build ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# Needed by sonar to get the git history for the branch the PR will be merged into.
with:
fetch-depth: 0
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: 'gradle'
- name: Test with coverage
run: ./gradlew --build-cache test jacocoTestReport
- name: SonarQube scan for library
run: ./gradlew --build-cache :library:sonar --info
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: SonarQube scan for cli
run: ./gradlew --build-cache :cli:sonar --info
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag:
needs: [ build, unit-tests-and-sonarqube, source-clear ]
uses: ./.github/workflows/tag.yml
if: success() && ${{ env.RUN_PUBLISH }}

Check failure on line 86 in .github/workflows/build-test-and-publish.yml

View workflow run for this annotation

GitHub Actions / Build, Test and Publish

Invalid workflow file

The workflow is not valid. .github/workflows/build-test-and-publish.yml (Line: 86, Col: 9): Unrecognized named-value: 'env'. Located at position 1 within expression: env.RUN_PUBLISH .github/workflows/build-test-and-publish.yml (Line: 92, Col: 9): Unrecognized named-value: 'env'. Located at position 1 within expression: env.RUN_PUBLISH
secrets: inherit
publish-library:
needs: [ tag ]
uses: ./.github/workflows/publish.yml
if: success() && ${{ env.RUN_PUBLISH }}
secrets: inherit
with:
tag: ${{ needs.tag.outputs.tag }}
release-cli:
needs: [ tag ]
uses: ./.github/workflows/release-cli.yml
secrets: inherit
if: success() && ${{ env.RUN_PUBLISH }}
with:
tag: ${{ needs.tag.outputs.tag }}
notify-slack-on-failure:
needs: [ build, unit-tests-and-sonarqube, source-clear, tag, publish-library, release-cli ]
runs-on: ubuntu-latest
if: failure() && github.ref == 'refs/heads/main'
steps:
- name: Notify slack on failure
uses: broadinstitute/[email protected]
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
with:
channel: '#dsp-analysis-journeys-alerts'
status: failure
author_name: Build on dev
fields: job,message
text: 'Build failed :sadpanda:'
username: 'Java-PFB GitHub Action'