Build and Test #141
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 and Test | |
on: | |
workflow_dispatch: | |
pull_request: | |
types: | |
- opened | |
- reopened | |
- synchronize | |
jobs: | |
authorize: | |
environment: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository && 'external' || 'internal' }} | |
runs-on: ubuntu-latest | |
steps: | |
- run: true | |
# build-test: | |
# needs: authorize | |
# uses: liquibase/build-logic/.github/workflows/os-extension-test.yml@main | |
# secrets: inherit | |
# with: | |
# extraMavenArgs: -Dtest="RedshiftDatabaseTest" | |
prepare-database: | |
name: Clean and initialize database | |
# needs: build-test | |
runs-on: ubuntu-latest | |
container: | |
image: liquibase/liquibase:latest | |
strategy: | |
fail-fast: false | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# - name: Download Artifacts | |
# uses: actions/download-artifact@v3 | |
# with: | |
# name: liquibase-redshift-artifacts | |
# # FIXME the redshift jar version should come from the pom.xml file | |
# - name: Download AWS Redshift driver | |
# run: wget https://s3.amazonaws.com/redshift-downloads/drivers/jdbc/2.1.0.14/redshift-jdbc42-2.1.0.14.jar | |
# - name: Add Redshift extension and driver to liquibase classpath | |
# run: | | |
# cp redshift-jdbc42-2.1.0.14.jar /liquibase/lib/ | |
# cp liquibase-redshift-*-SNAPSHOT.jar /liquibase/lib/ | |
- name: Setup Python | |
uses: actions/[email protected] | |
with: | |
python-version: '3.11.5' | |
- name: Start & Configure LocalStack | |
env: | |
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} | |
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} | |
run: | | |
# Install LocalStack and supporting tools | |
pip install localstack awscli-local | |
# Install Docker and start the service | |
apt-get update | |
apt-get install -y docker.io | |
service docker start | |
# Pull the required LocalStack Pro image | |
docker pull localstack/localstack-pro | |
# Start LocalStack with custom Redshift support | |
DOCKER_FLAGS='-e LOCALSTACK_API_KEY=${{ secrets.LOCALSTACK_API_KEY }}' localstack start -d | |
# Wait for LocalStack to fully start | |
echo "Waiting for LocalStack startup..." | |
localstack wait -t 30 | |
echo "Startup complete" | |
# Configure environment variables for Redshift | |
echo "TH_REDSHIFT_CLUSTER=my-redshift-cluster" >> $GITHUB_ENV | |
echo "TH_REDSHIFT_DB=exampledb" >> $GITHUB_ENV | |
echo "TH_REDSHIFT_USER=admin" >> $GITHUB_ENV | |
echo "TH_REDSHIFT_PASSWORD=examplePassword123" >> $GITHUB_ENV | |
echo "TH_REDSHIFT_PORT=5439" >> $GITHUB_ENV | |
echo "TH_REDSHIFT_REGION=us-east-1" >> $GITHUB_ENV | |
# Set up Redshift cluster in LocalStack | |
echo "Creating Redshift cluster in LocalStack..." | |
awslocal redshift create-cluster \ | |
--cluster-identifier $TH_REDSHIFT_CLUSTER \ | |
--db-name $TH_REDSHIFT_DB \ | |
--master-username $TH_REDSHIFT_USER \ | |
--master-user-password $TH_REDSHIFT_PASSWORD \ | |
--node-type dc2.large \ | |
--number-of-nodes 2 | |
# Fetch Redshift cluster endpoint | |
echo "Fetching Redshift cluster endpoint..." | |
REDSHIFT_ENDPOINT=$(awslocal redshift describe-clusters \ | |
--cluster-identifier $TH_REDSHIFT_CLUSTER \ | |
--query "Clusters[0].Endpoint.Address" \ | |
--output text) | |
# Construct Redshift URL | |
REDSHIFT_URL="jdbc:redshift://${REDSHIFT_ENDPOINT}:${TH_REDSHIFT_PORT}/${TH_REDSHIFT_DB}" | |
echo "REDSHIFT_URL=${REDSHIFT_URL}" >> $GITHUB_ENV | |
echo "Redshift cluster setup complete." | |
echo "Redshift URL: ${REDSHIFT_URL}" | |
- name: Clean AWS Redshift Database | |
run: liquibase --username="$TH_REDSHIFT_USER" --password="$TH_REDSHIFT_PASSWORD" --url="$REDSHIFT_URL" dropAll | |
- name: Init Database | |
run: liquibase --classpath="src/test/resources" --changeLogFile="harness.initScript.sql" --username="$TH_REDSHIFT_USER" --password="$TH_REDSHIFT_PASSWORD" --url="$REDSHIFT_URL" update | |
# integration-test: | |
# name: Test Harness for Redshift ${{ matrix.redshift }} | |
# needs: prepare-database | |
# runs-on: ubuntu-latest | |
# strategy: | |
# fail-fast: false | |
# matrix: | |
# redshift: [ "" ] | |
# steps: | |
# - uses: actions/checkout@v2 | |
# - name: Set up JDK | |
# uses: actions/setup-java@v3 | |
# with: | |
# java-version: 11 | |
# distribution: 'temurin' | |
# cache: 'maven' | |
# - name: Build Cache | |
# uses: actions/[email protected] | |
# with: | |
# key: build-${{ github.run_number }}-${{ github.run_attempt }} | |
# path: | | |
# **/target/** | |
# ~/.m2/repository/org/liquibase/ | |
# - name: Harness Test Run | |
# run: mvn -Dtest="LiquibaseHarnessSuiteIT" -DdbName=redshift -DdbUsername=${{secrets.TH_DB_ADMIN}} -DdbPassword=${{secrets.TH_DB_PASSWD}} -DdbUrl=${{secrets.TH_REDSHIFTURL}} test | |
# - name: Foundational Harness Test Run | |
# run: mvn -Dtest="LiquibaseHarnessFoundationalSuiteTest" -DdbName=redshift -DdbUsername=${{secrets.TH_DB_ADMIN}} -DdbPassword=${{secrets.TH_DB_PASSWD}} -DdbUrl=${{secrets.TH_REDSHIFTURL}} test | |
# - name: Advanced Harness Test Run | |
# run: mvn -Dtest="LiquibaseHarnessAdvancedSuiteTest" -DdbName=redshift -DdbUsername=${{secrets.TH_DB_ADMIN}} -DdbPassword=${{secrets.TH_DB_PASSWD}} -DdbUrl=${{secrets.TH_REDSHIFTURL}} test | |
# - name: Archive Redshift Test Results | |
# if: ${{ always() }} | |
# uses: actions/upload-artifact@v3 | |
# with: | |
# name: redshift-test-results | |
# path: build/spock-reports | |
# dependabot-automerge: | |
# needs: build-test | |
# uses: liquibase/build-logic/.github/workflows/dependabot-automerge.yml@main | |
# secrets: inherit |