github actions #1
This file contains hidden or 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: Backend CI | |
| on: | |
| push: | |
| branches-ignore: | |
| - main | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: 21 | |
| - name: Run Unit Tests | |
| run: | | |
| chmod +x gradlew | |
| ./gradlew clean test | |
| - name: Run SonarQube Analysis | |
| run: | | |
| ./gradlew sonar \ | |
| -Dsonar.projectKey=nus-mtechse-dmss_${{ github.event.repository.name }} \ | |
| -Dsonar.organization=nus-mtechse-dmss \ | |
| -Dsonar.host.url=https://sonarcloud.io \ | |
| -Dsonar.token=${{ secrets.SONAR_TOKEN }} | |
| integration-test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: 21 | |
| - name: Install tools | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y curl unzip netcat-openbsd | |
| - name: Install AWS CLI v2 | |
| run: | | |
| curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | |
| unzip awscliv2.zip | |
| sudo ./aws/install --update | |
| - name: Install SSM plugin | |
| run: | | |
| curl "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_64bit/session-manager-plugin.deb" -o "ssm.deb" | |
| sudo dpkg -i ssm.deb | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ap-southeast-1 | |
| - name: Check AWS identity | |
| run: aws sts get-caller-identity | |
| # 8️⃣ Start SSM tunnel | |
| - name: Start SSM tunnel | |
| run: | | |
| aws ssm start-session \ | |
| --target i-061983d3385eb80db \ | |
| --document-name AWS-StartPortForwardingSessionToRemoteHost \ | |
| --parameters '{"host":["swe5006-nus-g3-pg-dev.clee6i664xzo.ap-southeast-1.rds.amazonaws.com"],"portNumber":["5432"],"localPortNumber":["5432"]}' \ | |
| > ssm.log 2>&1 & | |
| echo "Waiting for tunnel..." | |
| for i in $(seq 1 30); do | |
| nc -z localhost 5432 && echo "Tunnel is up" && break | |
| echo "Waiting... ($i)" | |
| sleep 2 | |
| done | |
| echo "Tunnel log:" | |
| cat ssm.log || true | |
| - name: Run Integration Tests | |
| env: | |
| DB_HOST: localhost | |
| DB_PORT: 5432 | |
| DB_NAME: appdb | |
| DB_USERNAME: ${{ secrets.DB_USERNAME }} | |
| DB_PASSWORD: ${{ secrets.DB_PASSWORD }} | |
| run: | | |
| chmod +x gradlew | |
| ./gradlew clean integrationTest --info --stacktrace | |
| snyk-test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: 21 | |
| - name: Install Snyk | |
| run: npm install -g snyk | |
| - name: Snyk Auth | |
| run: snyk auth ${{ secrets.SNYK_TOKEN }} | |
| - name: Snyk Scan | |
| run: snyk test --all-sub-projects --severity-threshold=critical |