diff --git a/.github/workflows/database.yaml b/.github/workflows/database.yaml index 1ea8cb4..74e3ca9 100644 --- a/.github/workflows/database.yaml +++ b/.github/workflows/database.yaml @@ -7,68 +7,104 @@ on: jobs: test: + name: Test runs-on: ubuntu-latest services: - postgres: - image: postgres:9.6 - ports: - - 5432:5432 - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - options: >- - --health-cmd="pg_isready" - --health-interval=10s - --health-timeout=5s - --health-retries=5 + docker: + image: docker:19.03.12 + options: --privileged steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'adopt' - - - name: Cache Maven dependencies - uses: actions/cache@v3 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- - - - name: Run Maven Tests - run: | - mvn -e -Dfailsafe.rerunFailingTestsCount=3 -Dmaven.javadoc.skip=true \ - "-Dhsqldb.database.url=jdbc:hsqldb:file:target/hsqldb;shutdown=true" \ - -Dhsqldb.database.user=SA -Dhsqldb.database.password= \ - -Pcoverage,hsqldb verify - bash test-postgres.sh - bash test-sqlserver.sh - bash test-oracle.sh - mvn -e org.jacoco:jacoco-maven-plugin:report - - - name: Print Surefire reports on failure - if: failure() - run: | - echo "\n=== SUREFIRE REPORTS ===\n" - for F in target/surefire-reports/*.txt; do echo $F; cat $F; echo; done + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + + - name: Cache Maven packages + uses: actions/cache@v3 + with: + path: ~/.m2 + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Copy Maven settings + run: cp ./travis/maven-settings.xml $HOME/.m2/settings.xml + + - name: Modify pom.xml with Build Number + run: sed -i "s/-SNAPSHOT/-build-${{ github.run_number }}/" pom.xml + + - name: Set Timezone to America/Los_Angeles + run: | + sudo timedatectl set-timezone America/Los_Angeles + date + + - name: Authenticate to Google Cloud using Workload Identity Federation + uses: google-github-actions/auth@v2 + with: + project_id: 'som-rit-infrastructure-prod' + workload_identity_provider: 'projects/294515190965/locations/global/workloadIdentityPools/github/providers/susom-github' + + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@v2 + with: + version: '>= 363.0.0' + + - name: Configure Docker to use Google Artifact Registry + run: gcloud auth configure-docker us-west1-docker.pkg.dev + + - name: Run Maven Tests + run: | + mvn -e -Dfailsafe.rerunFailingTestsCount=3 -Dmaven.javadoc.skip=true \ + "-Dhsqldb.database.url=jdbc:hsqldb:file:target/hsqldb;shutdown=true" \ + -Dhsqldb.database.user=SA -Dhsqldb.database.password= -Pcoverage,hsqldb verify && + bash test-postgres.sh && + bash test-sqlserver.sh && + bash test-oracle.sh && + mvn -e org.jacoco:jacoco-maven-plugin:report sonar:sonar -Dsonar.projectKey=susom_database + + - name: Post Failure Reports + if: failure() + run: | + echo "\n=== SUREFIRE REPORTS ===\n" + for F in target/surefire-reports/*.txt; do echo $F; cat $F; echo; done deploy_snapshots: - runs-on: ubuntu-latest + name: Deploy Snapshots if: github.ref == 'refs/heads/master' && github.event_name == 'push' + runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'adopt' - - - name: Deploy Snapshots - run: | - mvn --batch-mode -e -DskipTests=true deploy \ No newline at end of file + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + + - name: Authenticate to Google Cloud using Workload Identity Federation + uses: google-github-actions/auth@v2 + with: + project_id: 'som-rit-infrastructure-prod' + workload_identity_provider: 'projects/294515190965/locations/global/workloadIdentityPools/github/providers/susom-github' + + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@v2 + with: + version: '>= 363.0.0' + + - name: Configure Docker to use Google Artifact Registry + run: gcloud auth configure-docker us-west1-docker.pkg.dev + + - name: Copy Maven settings + run: cp ./travis/maven-settings.xml $HOME/.m2/settings.xml + + - name: Modify pom.xml with Build Number + run: sed -i "s/-SNAPSHOT/-build-${{ github.run_number }}/" pom.xml + + - name: Deploy Snapshots to Artifact Registry + run: mvn --batch-mode -e -DskipTests=true deploy \ No newline at end of file