Merge pull request #899 from sncf-connect-tech/ldap-fix #195
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: Build, test and publish | |
on: # cf. https://gh.neting.ccmunity/t/how-to-trigger-an-action-on-push-or-pull-request-but-not-both/16662 | |
push: | |
branches: | |
- master | |
pull_request: | |
branches: | |
- master | |
workflow_dispatch: # = manually triggered | |
env: | |
DOCKER_IMAGE: hesperides/hesperides | |
IMAGE_TARBALL_FILENAME: hesperides-docker-image.tar | |
UPLOAD_NAME: docker-artifact | |
UPLOAD_PATH: artifacts | |
jobs: | |
maven-unit-and-functional-tests: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/setup-java@v1 | |
with: | |
java-version: 11 | |
- name: Maven cache | |
uses: actions/cache@v2 | |
with: | |
path: ~/.m2/repository | |
key: ${{ hashFiles('**/pom.xml') }} | |
- name: Launching tests with Maven | |
run: mvn test -pl '!tests/activedirectory-integration,!tests/mongo-integration,!tests/regression' | |
mongodb-integration-tests: | |
runs-on: ubuntu-latest | |
env: | |
# La paramètre `-Dspring.profiles.active` n'est plus pris en | |
# compte dans la commande Maven donc on définit les profils ici. | |
SPRING_PROFILES_ACTIVE: noldap,mongo | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/setup-java@v1 | |
with: | |
java-version: 11 | |
- name: Maven cache | |
uses: actions/cache@v2 | |
with: | |
path: ~/.m2/repository | |
key: ${{ hashFiles('**/pom.xml') }} | |
- uses: supercharge/mongodb-github-action@1.3.0 | |
with: | |
mongodb-version: 4.2 | |
- name: Install mongosh | |
# Il est désormais nécessaire d'installer mongosh à la main : | |
# https://github.com/actions/runner-images/issues/6626 | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y wget gnupg | |
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add - | |
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list | |
sudo apt-get update | |
sudo apt-get install -y mongodb-mongosh | |
mongosh hesperides mongo_create_collections.js | |
- name: Launching tests with Maven | |
run: | | |
mvn clean install -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -Djacoco.skip=true | |
# Le `&` est important pour ne pas bloquer le thread, d'où le `sleep 30` juste en dessous | |
mvn spring-boot:run -pl bootstrap & | |
# Give some time for the application to start: | |
sleep 30 | |
mvn -pl tests/mongo-integration verify | |
docker-build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Building Docker image | |
run: .github/workflows/docker_build.sh "${{ github.event.commits[0].message }}" | |
- run: mkdir -p $UPLOAD_PATH | |
- run: docker save $DOCKER_IMAGE:$GITHUB_SHA >$UPLOAD_PATH/$IMAGE_TARBALL_FILENAME | |
- uses: actions/upload-artifact@v2 | |
with: | |
name: ${{ env.UPLOAD_NAME }} | |
path: ${{ env.UPLOAD_PATH }} | |
retention-days: 1 | |
docker-push: | |
# Only perform this on master branch | |
# or on branches when triggered manually | |
if: github.ref == 'refs/heads/master' || github.event_name == 'workflow_dispatch' | |
runs-on: ubuntu-latest | |
needs: [ maven-unit-and-functional-tests, mongodb-integration-tests, docker-build ] | |
env: | |
DOCKER_USER: hesperides | |
DOCKER_PASS: ${{ secrets.DOCKER_PASS }} | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/download-artifact@v2 | |
with: | |
name: ${{ env.UPLOAD_NAME }} | |
path: ${{ env.UPLOAD_PATH }} | |
- run: docker load < $UPLOAD_PATH/$IMAGE_TARBALL_FILENAME | |
- name: Debug-display event name | |
run: echo ${{ github.event_name }} | |
- name: Deploying image to public Docker Hub | |
run: .github/workflows/docker_push.sh |