From d73f7bfe126149df7349e4947d307070d540be3e Mon Sep 17 00:00:00 2001 From: Mike Audi Date: Sat, 1 Apr 2023 02:21:59 -0500 Subject: [PATCH] update workflows for release + versioning --- .github/workflows/codeql.yml | 4 +- .github/workflows/release.yml | 87 ++++++++--------------------- .github/workflows/tests.yml | 4 +- .github/workflows/version.yml | 100 ++++++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+), 69 deletions(-) create mode 100644 .github/workflows/version.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 0761d23..92b2883 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -25,10 +25,10 @@ jobs: with: fetch-depth: 1 - - name: Set up JDK 19 + - name: Set up JDK uses: actions/setup-java@v3 with: - java-version: '19' + java-version: '20' distribution: 'zulu' - name: Initialize CodeQL diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 23eb709..66a0b90 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,69 +7,16 @@ on: types: - closed +permissions: + contents: write + id-token: write + # Cancel any active builds when new commits are pushed concurrency: group: ${{ github.ref }}-${{ github.workflow }} cancel-in-progress: true jobs: - bump_and_tag: - if: github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/') - runs-on: ubuntu-latest - environment: Production - services: - postgres: - image: postgres:14.5 - env: - POSTGRES_USER: tester - POSTGRES_PASSWORD: pgtestpw - POSTGRES_DB: l0_storage - POSTGRES_PORT: 5432 - ports: - - 5432:5432 - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Set up JDK 19 - uses: actions/setup-java@v3 - with: - java-version: '19' - distribution: 'zulu' - - - name: Install CLI - uses: dopplerhq/cli-action@v2 - - - name: Install PostgreSQL client - run: | - sudo apt-get update - sudo apt-get install --yes postgresql-client - - - name: Create Tables - run: psql -h localhost -d l0_storage -U tester -f database/create_tables.sql - env: - PGPASSWORD: pgtestpw - - - name: Maven Package - run: doppler run -c tst -- mvn clean package - env: - DOPPLER_TOKEN: ${{ secrets.DOPPLER_ST }} - - - name: Bump Version - id: bump-version - uses: RichardInnocent/semantic-versioning-maven@v0.0.36 - with: - access-token: ${{ secrets.github_token }} - version-prefix: - - outputs: - version: ${{ steps.bump-version.outputs.new-version }} test_and_push: runs-on: ubuntu-latest needs: bump_and_tag @@ -94,10 +41,10 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Set up JDK 19 + - name: Set up JDK uses: actions/setup-java@v3 with: - java-version: '19' + java-version: '20' distribution: 'zulu' - name: Install CLI @@ -126,6 +73,10 @@ jobs: - name: Registry login run: doctl registry login --expiry-seconds 600 + - name: Mvn project version + id: version + run: echo "version=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)" >> $GITHUB_OUTPUT + - name: Build and push uses: docker/build-push-action@v4 with: @@ -133,13 +84,17 @@ jobs: file: Dockerfile push: true tags: | - registry.digitalocean.com/tiki/l0-storage:${{ needs.bump_and_tag.outputs.version }} + registry.digitalocean.com/tiki/l0-storage:${{ steps.version.outputs.version }} registry.digitalocean.com/tiki/l0-storage:latest build-args: | JAR_FILE=target/*.jar + + outputs: + version: ${{ steps.version.outputs.version }} + deploy_to_infra: runs-on: ubuntu-latest - needs: [ bump_and_tag, test_and_push ] + needs: [ test_and_push ] environment: Production steps: - name: Checkout @@ -171,6 +126,7 @@ jobs: id: apply run: terraform apply -auto-approve working-directory: infra + sentry_release: runs-on: ubuntu-latest needs: deploy_to_infra @@ -189,9 +145,10 @@ jobs: environment: public ignore_missing: true ignore_empty: true + publish_docs: runs-on: ubuntu-latest - needs: [ sentry_release, bump_and_tag ] + needs: [ sentry_release, test_and_push ] environment: Production steps: - name: Checkout @@ -200,9 +157,9 @@ jobs: - name: OpenApi uses: readmeio/rdme@8.5.0 with: - rdme: openapi docs/openapi.yaml --key=${{ secrets.README_API_KEY }} --id=6379efc05c98fc002512b213 + rdme: openapi openapi.yaml --key=${{ secrets.README_API_KEY }} --id=6379efc05c98fc002512b213 - name: Release - uses: softprops/action-gh-release@v1 + uses: ncipollo/release-action@v1 with: - tag_name: ${{ needs.bump_and_tag.outputs.version }} + tag: ${{ needs.test_and_push.outputs.version }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0c7832c..34c4833 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -33,10 +33,10 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Set up JDK 19 + - name: Set up JDK uses: actions/setup-java@v3 with: - java-version: '19' + java-version: '20' distribution: 'zulu' - name: Install CLI diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml new file mode 100644 index 0000000..86b06e3 --- /dev/null +++ b/.github/workflows/version.yml @@ -0,0 +1,100 @@ +name: Version + +on: + pull_request: + branches: + - main + +# Cancel any active builds when new commits are pushed +concurrency: + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true + +jobs: + Version: + if: startsWith(github.head_ref, 'release/') + runs-on: ubuntu-latest + services: + postgres: + image: postgres:14.5 + env: + POSTGRES_USER: tester + POSTGRES_PASSWORD: pgtestpw + POSTGRES_DB: l0_storage + POSTGRES_PORT: 5432 + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up JDK + uses: actions/setup-java@v3 + with: + java-version: '20' + distribution: 'zulu' + + - name: Checkout PR + id: getpr + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh pr checkout ${{ github.event.pull_request.number }} + export PR_BRANCH=$(git branch --show-current) + echo "branch=$PR_BRANCH" >> $GITHUB_OUTPUT + + - name: Get Version + id: semver + uses: ietf-tools/semver-action@v1 + with: + token: ${{ github.token }} + branch: ${{ steps.getpr.outputs.branch }} + + - name: Set Version + run: | + sed -i '0,/*.*.*<\/version>/s//${{ steps.semver.outputs.nextStrict }}<\/version>/' pom.xml + + - name: Set up JDK + uses: actions/setup-java@v3 + with: + java-version: '20' + distribution: 'zulu' + + - name: Install CLI + uses: dopplerhq/cli-action@v2 + + - name: Install PostgreSQL client + run: | + sudo apt-get update + sudo apt-get install --yes postgresql-client + + - name: Create Tables + run: psql -h localhost -d l0_storage -U tester -f database/create_tables.sql + env: + PGPASSWORD: pgtestpw + + - name: OAS3 + run: doppler run -c tst -- mvn clean verify + env: + DOPPLER_TOKEN: ${{ secrets.DOPPLER_ST }} + + - name: Commit Changes + continue-on-error: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + git config --global user.email "action@github.com" + git config --global user.name "GH Action" + git add pom.xml + git add openapi.yaml + git commit -m 'version bump' + git push + + outputs: + version: ${{ steps.semver.outputs.nextStrict }}