Skip to content

update

update #13

Workflow file for this run

# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: Java CI with Maven
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
POSTGRES_DB: e-comm02
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
cache: maven
- name: Download wait-for-it.sh
run: |
curl -o wait-for-it.sh https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh
chmod +x wait-for-it.sh
- name: Wait for PostgreSQL
run: ./wait-for-it.sh postgres:5432 -t 120
- name: Check PostgreSQL service
run: |
nc -zv *** 5432
pg_isready -h *** -p 5432
# - name: Cache Maven packages
# uses: actions/cache@v2
# with:
# path: ~/.m2
# key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
# restore-keys: ${{ runner.os }}-m2
- name: Build with Maven
run: mvn clean install
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
- name: Check PostgreSQL Connection
run: |
sudo apt-get -y install postgresql-client
psql -h postgres -U ${{ secrets.POSTGRES_USER }} -d ${{ secrets.POSTGRES_DB }} -c 'SELECT NOW()'
env:
PGPASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
- name: Test with Maven
run: mvn test
env:
DATABASE_URL: jdbc:postgresql://postgres:5432/e-comm02
- name: Deploy to GitHub Releases (Simple Example)
if: startsWith(github.ref, 'refs/tags/')
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./target/ecomm-0.0.1-SNAPSHOT.jar # replace with your artifact's path
asset_name: ecomm-0.0.1-SNAPSHOT.jar
asset_content_type: application/jar
- name: Build and push docker image
uses: mr-smithers-excellent/docker-build-push@v6
with:
image: hahaha12353/backend
tags: latest
registry: docker.io
dockerfile: Dockerfile
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
# - name: Update dependency graph
# uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6