Included PuttingAllTogether
as module
#17
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: 'PuttingAllTogether CI/CD' | |
on: push | |
env: | |
JAVA_VERSION: 20 | |
UPLOADED_ARTIFACTS_DIR: 'gh-pages' | |
SITE_DIR: 'gh-pages/site' | |
MODULE_DIR: 'PuttingAllTogether' | |
TARGET_DIR: 'PuttingAllTogether/target' | |
TEST_RESULTS_DIR: 'PuttingAllTogether/target/test-results' | |
JACOCO_EXECS_DIR: 'PuttingAllTogether/target/gh-pages-*t/test-results/jacoco-execs' | |
JACOCO_BADGES_DIR: 'gh-pages/site/jacoco-merged/jacoco-resources/badges' | |
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-combined-coverage-report: | |
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: 'Set up the Oracle JDK `${{ env.JAVA_VERSION }}`' | |
uses: './.github/actions/install-java' | |
with: | |
JAVA_VERSION_TO_INSTALL: ${{ env.JAVA_VERSION }} | |
- name: 'Download the ut and it test results to generate the combined coverage report' | |
# this step should be in a separate job which should depend on both ut and it | |
# so both of them are available to generate the combine coverage report | |
uses: actions/download-artifact@v3 | |
with: | |
path: ${{ env.TARGET_DIR }} | |
- name: 'Display structure of downloaded files' | |
run: ls -R | |
working-directory: ${{ env.TARGET_DIR }} | |
- name: 'Place the Jacoco code coverage files in `${{ env.JACOCO_EXECS_DIR }}`' | |
run: | | |
mkdir -p ${{ env.TEST_RESULTS_DIR }} | |
cp -r ${{ env.JACOCO_EXECS_DIR }} ${{ env.TEST_RESULTS_DIR }} | |
- name: 'Generate the merged code coverage report' | |
run: mvn -Djacoco.haltOnFailure=false post-integration-test -P nt --file ${{ env.MODULE_DIR }}/pom.xml | |
- name: 'Uploads the results to `${{ env.UPLOADED_ARTIFACTS_DIR }}` folder' | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.UPLOADED_ARTIFACTS_DIR }} | |
retention-days: 1 | |
path: ${{ env.TARGET_DIR }} | |
generate-project-site: | |
runs-on: ubuntu-latest | |
needs: generate-combined-coverage-report | |
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 }} | |
REQUIRES_TESTS: true | |
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: 'Deploy the project''s site to GitHub Pages' | |
uses: './.github/actions/deploy-to-gh-pages' | |
with: | |
JAVA_VERSION_TO_INSTALL: ${{ env.JAVA_VERSION }} | |
UPLOADED_ARTIFACTS_DIR: ${{ env.UPLOADED_ARTIFACTS_DIR }} | |
MODULE_DIR: ${{ env.MODULE_DIR }} | |
SITE_DIR: ${{ env.SITE_DIR }} | |
JACOCO_BADGES_DIR: ${{ env.JACOCO_BADGES_DIR }} | |
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 }} |