CI #15909
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: CI | |
on: | |
push: | |
pull_request: | |
schedule: | |
# launch a build every day on develop | |
- cron: '0 22 * * *' | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
inputs: | |
build: | |
description: 'Build' | |
required: false | |
default: 'true' | |
karate: | |
description: 'Karate tests' | |
required: false | |
default: 'true' | |
cypress: | |
description: 'Cypress Tests' | |
required: false | |
default: 'true' | |
cypressTestFiles: | |
description: 'Cypress Test files' | |
required: false | |
default: '*' | |
doc: | |
description: 'Build and publish documentation ' | |
required: false | |
default: 'false' | |
docLatest: | |
description: 'Build and publish documentation - Latest' | |
required: false | |
default: 'false' | |
dockerPush: | |
description: 'Docker push' | |
required: false | |
default: 'false' | |
dockerPushLatest: | |
description: 'Docker push - Latest' | |
required: false | |
default: 'false' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
if: ${{ github.event.inputs.dockerPush != 'true' && github.event.inputs.dockerPushLatest != 'true' && github.event.inputs.doc != 'true' && github.event.inputs.docLatest != 'true' && github.event_name != 'schedule' && github.ref_name != 'master' }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Job status | |
run: | | |
export OF_VERSION=$(<VERSION) | |
echo "----------------------------" | |
echo "Trigger by : ${{ github.event_name }}" | |
echo "On branch : ${{ github.ref_name }} " | |
echo "PR source branch : ${{ github.head_ref }} " | |
echo "PR target branch : ${{ github.base_ref }} " | |
echo "Opfab Version : ${OF_VERSION}" | |
echo "---------------------------" | |
- name: Cache Gradle packages | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('gradle.properties','**/*.gradle') }} | |
restore-keys: ${{ runner.os }}-gradle | |
# Install all required tools | |
- name: Install | |
run: ./CICD/github/install.sh | |
- name: Build | |
if: ${{ github.event.inputs.build == 'true' || github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push'}} | |
# build.sh set variable for sdk, nvm and gradle | |
# if variable is set in install step it is not accessible in this step | |
run: ./CICD/github/build.sh | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# SonarCloud access token should be generated from https://sonarcloud.io/account/security/ | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
- name: Karate tests | |
if: ${{ github.event.inputs.karate == 'true' || github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' }} | |
run: ./CICD/github/launch_karate_tests.sh | |
- name: Cypress tests | |
if: ${{ github.event.inputs.cypress == 'true' || github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' }} | |
run: ./CICD/github/launch_cypress_tests.sh ${{ github.event.inputs.cypressTestFiles }} | |
- name: Upload cypress screenshots and logs | |
uses: actions/upload-artifact@v4 | |
if: failure() | |
with: | |
name: cypress-screenshots | |
path: | | |
src/test/cypress/cypress/screenshots | |
opfab.log | |
publish: | |
runs-on: ubuntu-latest | |
environment: publishVersion | |
if: ${{ github.event.inputs.dockerPush == 'true' || github.event.inputs.dockerPushLatest == 'true' || github.event.inputs.doc == 'true' || github.event.inputs.docLatest == 'true' || github.event_name == 'schedule' || github.ref_name == 'master' }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Job status | |
run: | | |
export OF_VERSION=$(<VERSION) | |
echo "----------------------------" | |
echo "Trigger by : ${{ github.event_name }}" | |
echo "On branch : ${{ github.ref_name }} " | |
echo "PR source branch : ${{ github.head_ref }} " | |
echo "PR target branch : ${{ github.base_ref }} " | |
echo "Opfab Version : ${OF_VERSION}" | |
echo "---------------------------" | |
- name: Cache Gradle packages | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('gradle.properties','**/*.gradle') }} | |
restore-keys: ${{ runner.os }}-gradle | |
# Install all required tools | |
- name: Install | |
run: ./CICD/github/install.sh | |
- name: Build | |
if: ${{ github.event.inputs.build == 'true' || github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push'}} | |
# set variable in this step (sdk, nvm et gradle) | |
# if variable is set in install step it is not accessible in this step | |
run: ./CICD/github/build.sh | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# SonarCloud access token should be generated from https://sonarcloud.io/account/security/ | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
- name: Karate tests | |
if: ${{ github.event.inputs.karate == 'true' || github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' }} | |
run: ./CICD/github/launch_karate_tests.sh | |
- name: Cypress tests | |
if: ${{ github.event.inputs.cypress == 'true' || github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' }} | |
run: ./CICD/github/launch_cypress_tests.sh | |
- name: Upload cypress screenshots | |
uses: actions/upload-artifact@v4 | |
if: failure() | |
with: | |
name: cypress-screenshots | |
path: src/test/cypress/cypress/screenshots | |
- name : Publish Documentation | |
if : ${{ github.event.inputs.doc == 'true' || github.event_name == 'schedule'}} | |
run: | | |
source $HOME/.sdkman/bin/sdkman-init.sh; | |
export NVM_DIR="$HOME/.nvm" | |
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm | |
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion | |
source ./bin/load_environment_light.sh; | |
./gradlew --build-cache generateSwaggerUI asciidoctor; | |
./CICD/github/upload_doc.sh | |
env: | |
GH_DOC_TOKEN: ${{ secrets.GH_DOC_TOKEN}} | |
- name : Publish Documentation (latest) | |
if : ${{ github.event.inputs.docLatest == 'true' || github.ref_name == 'master'}} | |
run: | | |
source $HOME/.sdkman/bin/sdkman-init.sh; | |
export NVM_DIR="$HOME/.nvm" | |
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm | |
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion | |
source ./bin/load_environment_light.sh; | |
./gradlew --build-cache generateSwaggerUI asciidoctor; | |
./CICD/github/upload_doc.sh --updateLatest true | |
env: | |
GH_DOC_TOKEN: ${{ secrets.GH_DOC_TOKEN}} | |
- name : Push images to dockerhub | |
if: ${{ github.event.inputs.dockerPush == 'true' || github.event_name == 'schedule' || github.ref_name == 'master' }} | |
run: | | |
echo ${{ secrets.DOCKER_TOKEN }} | docker login --username opfabtravis --password-stdin | |
docker images --format "{{.Repository}}:{{.Tag}}" | grep lfe | while read image; do | |
echo push ${image} | |
docker push ${image} | |
done | |
- name : Push images latest to dockerhub | |
if: ${{ github.event.inputs.dockerPushLatest == 'true' || github.ref_name == 'master' }} | |
run: | | |
echo ${{ secrets.DOCKER_TOKEN }} | docker login --username opfabtravis --password-stdin | |
docker images --format "{{.Repository}}:{{.Tag}}" | grep lfe | while read image; do | |
export repository=$(echo ${image} | cut -d ":" -f 1) | |
echo "create tag latest for ${repository}" | |
docker tag ${image} ${repository}:latest | |
docker push ${repository}:latest | |
done | |