Skip to content

In case of multimodule setup, the gh-pages deployment job finishing l… #4

In case of multimodule setup, the gh-pages deployment job finishing l…

In case of multimodule setup, the gh-pages deployment job finishing l… #4

name: 'JAVA CI/CD'
on: push
env:
JAVA_VERSION: 20
UPLOADED_ARTIFACTS_DIR: 'gh-pages'
SITE_DIR: 'gh-pages/site'
MODULE_DIR: 'PuttingAllTogether'
BRANCHES_COVERAGE_THRESHOLD: '60%'
INSTRUCTIONS_COVERAGE_THRESHOLD: '60%'
jobs:
setup-env:
runs-on: ubuntu-latest
outputs:
JAVA_VERSION: ${{steps.setup-env.outputs.JAVA_VERSION}}
MODULE_DIR: ${{steps.setup-env.outputs.MODULE_DIR}}
steps:
- name: 'Setup Environment'
id: setup-env
run: |
echo "JAVA_VERSION=${{ env.JAVA_VERSION }}" >> $GITHUB_OUTPUT
echo "MODULE_DIR=${{ env.MODULE_DIR }}" >> $GITHUB_OUTPUT
build:
runs-on: ubuntu-latest
steps:
- name: 'Get the latest code from the `${{ github.repository }}` repository'
uses: actions/checkout@v3
- name: 'Set up the Oracle JDK `${{ env.JAVA_VERSION }}`'
uses: './.github/actions/install-java'
with:
JAVA_VERSION_TO_INSTALL: ${{ env.JAVA_VERSION }}
- name: 'Cache Maven packages'
uses: actions/cache@v2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2-*
- name: 'Compiles the application code'
run: mvn clean compile --file ${{ env.MODULE_DIR }}/pom.xml
unit-tests:
runs-on: ubuntu-latest
steps:
- name: 'Get the latest code from the `${{ github.repository }}` repository'
uses: actions/checkout@v3
- name: 'Runs the unit tests and uploads the results'
uses: './.github/actions/run-tests-and-upload-results'
with:
RUN_UNIT_TESTS: true
JAVA_VERSION_TO_INSTALL: ${{ env.JAVA_VERSION }}
UPLOADED_ARTIFACTS_DIR: ${{ env.UPLOADED_ARTIFACTS_DIR }}
MODULE_DIR: ${{ env.MODULE_DIR }}
integration-tests:
runs-on: ubuntu-latest
steps:
- name: 'Get the latest code from the `${{ github.repository }}` repository'
uses: actions/checkout@v3
- name: 'Runs the integration tests and uploads the results'
uses: './.github/actions/run-tests-and-upload-results'
with:
RUN_UNIT_TESTS: false
JAVA_VERSION_TO_INSTALL: ${{ env.JAVA_VERSION }}
UPLOADED_ARTIFACTS_DIR: ${{ env.UPLOADED_ARTIFACTS_DIR }}
MODULE_DIR: ${{ env.MODULE_DIR }}
generate-project-site:
runs-on: ubuntu-latest
needs:
- unit-tests
- integration-tests
steps:
- name: 'Get the latest code from the `${{ github.repository }}` repository'
uses: actions/checkout@v3
- name: 'Generates the project''s site'
uses: './.github/actions/generate-reports'
with:
JAVA_VERSION_TO_INSTALL: ${{ env.JAVA_VERSION }}
UPLOADED_ARTIFACTS_DIR: ${{ env.UPLOADED_ARTIFACTS_DIR }}
MODULE_DIR: ${{ env.MODULE_DIR }}
generate-code-coverage-badge:
if: ${{ github.ref == 'refs/heads/master' }}
runs-on: ubuntu-latest
needs: generate-project-site
steps:
- name: 'Download the uploaded artifacts to `${{ env.UPLOADED_ARTIFACTS_DIR }}` folder'
uses: actions/download-artifact@v3
with:
name: ${{ env.UPLOADED_ARTIFACTS_DIR }}
path: ${{ env.UPLOADED_ARTIFACTS_DIR }}
- name: 'Generate and upload JaCoCo Code Coverage Badge'
id: jacoco
uses: cicirello/jacoco-badge-generator@v2
with:
generate-branches-badge: true
fail-if-branches-less-than: ${{ env.BRANCHES_COVERAGE_THRESHOLD }}
fail-if-coverage-less-than: ${{ env.INSTRUCTIONS_COVERAGE_THRESHOLD }}
badges-directory: 'site/badges/jacoco/svgs'
jacoco-csv-file: ${{ env.SITE_DIR }}/jacoco-merged/jacoco.csv
- name: 'Log code coverage percentage'
run: |
echo "coverage = ${{ steps.jacoco.outputs.coverage }}"
echo "branch coverage = ${{ steps.jacoco.outputs.branches }}"
- name: 'Upload JaCoCo code coverage badge to `${{ env.UPLOADED_ARTIFACTS_DIR }}` folder'
uses: actions/upload-artifact@v3
with:
name: ${{ env.UPLOADED_ARTIFACTS_DIR }}
retention-days: 1
path: 'site/badges/jacoco'
deploy-to-gh-pages:
needs: generate-code-coverage-badge
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: 'Get the latest code from the `${{ github.repository }}` repository'
uses: actions/checkout@v3
- name: 'Set up the Oracle JDK `${{ env.JAVA_VERSION }}`'
uses: './.github/actions/install-java'
with:
JAVA_VERSION_TO_INSTALL: ${{ env.JAVA_VERSION }}
- name: 'Download the uploaded artifacts to `${{ env.UPLOADED_ARTIFACTS_DIR }}` folder'
uses: actions/download-artifact@v3
with:
name: ${{ env.UPLOADED_ARTIFACTS_DIR }}
path: ${{ env.UPLOADED_ARTIFACTS_DIR }}
- name: 'Copy the `README.md` file to `${{ env.SITE_DIR }}` folder'
run: cp README.md ${{ env.SITE_DIR }}
- name: 'Copy the `LICENSE` file to `${{ env.SITE_DIR }}` folder'
run: cp LICENSE ${{ env.SITE_DIR }}
- name: 'Copy the Jacoco badges file to the relevant folder'
run: |
mkdir -p ${{ env.SITE_DIR }}/jacoco-merged/jacoco-resources/badges
cp ${{ env.UPLOADED_ARTIFACTS_DIR }}/svgs/* ${{ env.SITE_DIR }}/jacoco-merged/jacoco-resources/badges
rm -rf ${{ env.UPLOADED_ARTIFACTS_DIR }}/svgs
# - name: 'Create `INDIVIDUAL_MODULES` folder and place it in `${{ env.SITE_DIR }}` with site contents'
# #Adding a new `INDIVIDUAL_MODULES` folder inside `site` folder to contain individual modules deployed site.
# #It's just to avoid the overwriting of the contents deployed by the `parent pom` in the `gh-pages` branch.
# run: |
# mkdir -p INDIVIDUAL_MODULES/${{ env.MODULE_DIR }}
# mv ${{ env.SITE_DIR }}/* INDIVIDUAL_MODULES/${{ env.MODULE_DIR }}
# mv INDIVIDUAL_MODULES ${{ env.SITE_DIR }}
- name: 'Deploy to GitHub Pages'
if: ${{ github.ref == 'refs/heads/master' }}
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: ${{ env.SITE_DIR }}
# to push the contents of the deployment folder into a specific directory on the deployment branch
target-folder: INDIVIDUAL_MODULES/${{ env.MODULE_DIR }}
clean-exclude: staging
deploy-to-gh-packages:
needs:
- setup-env
- unit-tests
- integration-tests
permissions:
contents: read
packages: write
uses: './.github/workflows/deploy.yml'
with:
JAVA_VERSION_TO_INSTALL: ${{ needs.setup-env.outputs.JAVA_VERSION }}
MODULE_DIR: ${{ needs.setup-env.outputs.MODULE_DIR }}