Pipeline GitHub action byos #2
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: Build Pipeline | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
# runs-on: depot-ubuntu-22.04 | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: "17" | |
distribution: "temurin" | |
- name: Build with Gradle | |
run: ./gradlew build -x test | |
test: | |
needs: build | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: postgres:15 | |
env: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres | |
POSTGRES_DB: sakila | |
ports: | |
- 5432:5432 | |
options: >- | |
--health-interval=10s | |
--health-timeout=5s | |
--health-retries=5 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: "17" | |
distribution: "temurin" | |
- name: Install PostgreSQL Client | |
run: sudo apt-get update && sudo apt-get install -y postgresql-client | |
- name: Wait for PostgreSQL to be Fully Ready | |
run: | | |
until PGPASSWORD=postgres psql -h localhost -U postgres -d sakila -c "SELECT 1" > /dev/null 2>&1; do | |
echo "Waiting for database to be fully ready..." | |
sleep 2 | |
done | |
echo "Database is fully ready!" | |
- name: Load Data into PostgreSQL | |
run: | | |
PGPASSWORD=postgres psql -h localhost -U postgres -d sakila -f src/test/resources/full_dump.sql | |
- name: Test with Gradle | |
run: ./gradlew test | |
deploy: | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: "17" | |
distribution: "temurin" | |
- name: Replace "SNAPSHOT" within POM version with date, build number and commit hash | |
run: | | |
snapshot_version=$(grep "^snapshot_version=" version.properties | cut -d'=' -f2) | |
echo "SNAPSHOT_VERSION=$snapshot_version" >> $GITHUB_ENV | |
date=$(date -u +%Y%m%d%H%M) | |
release_candidate_version=${major_minor_patch}${date}-${{ github.run_number }}-${GITHUB_SHA::7} | |
echo "RELEASE_CANDIDATE_VERSION=$release_candidate_version" >> $GITHUB_ENV | |
sed -i "s/^version=.*/version=${release_candidate_version}/" version.properties | |
echo "VERSION" version | |
- name: Publish to Nexus Repository | |
run: ./gradlew publish -PbuildNumber=${{ github.run_number }} -PbuildRevision=${GITHUB_SHA} -Pversion=${RELEASE_CANDIDATE_VERSION} | |
env: | |
NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }} | |
NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }} | |
- name: Build summary | |
run: | | |
echo "### Build successful! :rocket:" >> $GITHUB_STEP_SUMMARY | |
echo "- Version \`$RELEASE_CANDIDATE_VERSION\`" >> $GITHUB_STEP_SUMMARY | |