From 3fb5611478372ebee6734665e300ad99c9aed309 Mon Sep 17 00:00:00 2001 From: Mark Patton Date: Wed, 13 Dec 2023 15:15:46 -0500 Subject: [PATCH] Switch to reusable workflows --- .github/workflows/ci.yml | 34 +------ .github/workflows/release.yml | 158 +++-------------------------- .github/workflows/snapshot.yml | 14 +++ .github/workflows/update-image.yml | 47 --------- 4 files changed, 30 insertions(+), 223 deletions(-) create mode 100644 .github/workflows/snapshot.yml delete mode 100644 .github/workflows/update-image.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4f9ef198..44af88ea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,33 +1,7 @@ -name: pass-core Continuous Integration -on: [ pull_request, workflow_dispatch ] - -concurrency: - group: ci-${{ github.head_ref || github.ref }} - cancel-in-progress: true +name: Continuous Integration +on: [pull_request, workflow_dispatch] jobs: - print-workflow-description: - runs-on: ubuntu-latest - steps: - - run: echo "This is a CI build of branch ${{ github.ref }} in repository ${{ github.repository }}" - - run: echo "This job was triggered by a ${{ github.event_name }} event and is running on a ${{ runner.os }} server" - - run-tests: + test: name: "Run Unit & Integration Tests" - runs-on: ubuntu-latest - steps: - - name: "Checkout the repository" - uses: actions/checkout@v2 - - name: "Set up JDK 17" - uses: actions/setup-java@v3 - with: - java-version: 17 - distribution: 'temurin' - - name: "Cache Maven packages" - uses: actions/cache@v2 - with: - path: ~/.m2 - key: ${{ runner.os }}-m3-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m3 - - name: "Run unit & integration tests" - run: mvn -U -B -V -ntp verify --file pom.xml + uses: eclipse-pass/main/.github/workflows/ci.yml@combined-release diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cbe06ea5..dea631b0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,5 @@ -name: "Publish: full release OR snapshot" +# Test +name: Publish Release on: workflow_dispatch: @@ -9,151 +10,16 @@ on: nextversion: description: 'Next dev version' required: true - push: - branches: - - 'main' -jobs: - setup: - runs-on: ubuntu-latest - outputs: - # Output project version from the POM to conditionally run dependent steps - project-version: ${{ steps.project_version.outputs.version }} - steps: - - name: Checkout latest code - uses: actions/checkout@v3 - - - name: Setup Java & Maven - uses: actions/setup-java@v3 - with: - java-version: 17 - distribution: 'temurin' - cache: 'maven' - - - name: Get project version from POM - id: project_version - run: echo "VERSION=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout`" >> $GITHUB_OUTPUT - - # Run only if project POM has version ending in "-SNAPSHOT" - snapshot: - needs: setup - if: github.event_name == 'push' && endsWith(needs.setup.outputs.project-version, '-SNAPSHOT') - runs-on: ubuntu-latest - steps: - - name: Checkout latest code - uses: actions/checkout@v3 - - - name: Setup Java & Maven - uses: actions/setup-java@v3 - with: - java-version: 17 - distribution: 'temurin' - cache: 'maven' - server-id: ossrh - server-username: MAVEN_USERNAME - server-password: MAVEN_PASSWORD - gpg-private-key: ${{ secrets.MAVEN_GPG_KEY }} - gpg-passphrase: MAVEN_GPG_PASSPHRASE - - - name: Publish SNAPSHOT - run: mvn -B --no-transfer-progress clean deploy - env: - MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} - MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} - MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} +env: + RELEASE: ${{ inputs.releaseversion }} + NEXT: ${{ inputs.nextversion}} - # Run for manual trigger (workflow dispatch), since you'll have release and next dev versions specified - # All commits will have a -SNAPSHOT project version anyway, since the releases will be handled here +jobs: release: - needs: setup - if: github.event_name == 'workflow_dispatch' - runs-on: ubuntu-latest - env: - RELEASE: ${{ inputs.releaseversion }} - NEXT: ${{ inputs.nextversion }} - steps: - - name: Checkout latest code - uses: actions/checkout@v3 - - - name: Config git user - run: | - git config user.name ${{ github.actor }} - git config user.email "${{ github.actor }}@users.noreply.github.com" - - - name: Setup Java & Maven - uses: actions/setup-java@v3 - with: - java-version: 17 - distribution: 'temurin' - cache: 'maven' - server-id: ossrh - server-username: MAVEN_USERNAME - server-password: MAVEN_PASSWORD - gpg-private-key: ${{ secrets.MAVEN_GPG_KEY }} - gpg-passphrase: MAVEN_GPG_PASSPHRASE - # ============================================================================= - # Start the release - # ============================================================================= - - name: Run tests - run: mvn -B -U -V -ntp verify - - - name: Bump version to release - run: mvn -B -U -V -ntp versions:update-parent -DparentVersion=$RELEASE - - - name: Commit release version bump - uses: EndBug/add-and-commit@v9 - with: - add: pom.xml **/pom.xml - message: "Update parent version to $RELEASE" - - # Maven Release Plugin is currently configured to hook into the install phase, so tests would normally be run - # Since we ran tests at the start of this process, skip tests here to save some time - - name: Release main POM - run: | - mvn -B -U -V -ntp release:prepare -DreleaseVersion=$RELEASE -Dtag=$RELEASE -DdevelopmentVersion=$NEXT -DskipTests -Darguments=-DskipTests - mvn -B -U -V -ntp release:perform -P release -DskipTests -Darguments=-DskipTests - env: - MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} - MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} - MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} - - - name: Update parent POM to new dev version - run: mvn -B -U -V -ntp versions:update-parent -DallowSnapshots=true -DparentVersion=$NEXT - - - name: Commit snapshot version bump - uses: EndBug/add-and-commit@v9 - with: - add: pom.xml **/pom.xml - message: "Update parent version to $NEXT" - push: true - - - name: Build and publish new dev version - run: mvn -B -U -V -ntp deploy -P release -DskipTests - env: - MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} - MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} - MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} - - - name: Push new release tag GH - run: git push origin --tags - - # Handle Docker images - - name: Login to GHCR - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Push Docker image to GHCR - run: | - docker push ghcr.io/eclipse-pass/deposit-services-core:$RELEASE - docker push ghcr.io/eclipse-pass/deposit-services-core:$NEXT - docker push ghcr.io/eclipse-pass/pass-notification-service:$RELEASE - docker push ghcr.io/eclipse-pass/pass-notification-service:$NEXT - docker push ghcr.io/eclipse-pass/jhu-grant-loader:$RELEASE - docker push ghcr.io/eclipse-pass/jhu-grant-loader:$NEXT - docker push ghcr.io/eclipse-pass/pass-journal-loader:$RELEASE - docker push ghcr.io/eclipse-pass/pass-journal-loader:$NEXT - docker push ghcr.io/eclipse-pass/pass-nihms-loader:$RELEASE - docker push ghcr.io/eclipse-pass/pass-nihms-loader:$NEXT + uses: eclipse-pass/main/.github/workflows/release.yml@combined-release + secrets: inherit + with: + releaseversion: ${{ inputs.releaseversion }} + nextversion: ${{ inputs.nextversion}} + images: ghcr.io/eclipse-pass/deposit-services-core ghcr.io/eclipse-pass/pass-notification-service ghcr.io/eclipse-pass/jhu-grant-loader ghcr.io/eclipse-pass/pass-journal-loader ghcr.io/eclipse-pass/pass-nihms-loader diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml new file mode 100644 index 00000000..c6460154 --- /dev/null +++ b/.github/workflows/snapshot.yml @@ -0,0 +1,14 @@ +name: Publish SNAPSHOT + +on: + push: + branches: + - 'main' + workflow_dispatch: + +jobs: + snapshot: + uses: eclipse-pass/main/.github/workflows/snapshot.yml@combined-release + secrets: inherit + with: + images: ghcr.io/eclipse-pass/deposit-services-core ghcr.io/eclipse-pass/pass-notification-service ghcr.io/eclipse-pass/jhu-grant-loader ghcr.io/eclipse-pass/pass-journal-loader ghcr.io/eclipse-pass/pass-nihms-loader diff --git a/.github/workflows/update-image.yml b/.github/workflows/update-image.yml deleted file mode 100644 index 46b63274..00000000 --- a/.github/workflows/update-image.yml +++ /dev/null @@ -1,47 +0,0 @@ -# This workflow will update the pass-support Docker images in GHCR and update the pass-support config -# in pass-docker - -name: Update Docker image - -on: - workflow_dispatch: - push: - branches: [main] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - # Update pass-support Docker images in GHCR - - name: Check out latest pass-support - uses: actions/checkout@v3 - - - name: "Set up JDK 17" - uses: actions/setup-java@v3 - with: - java-version: 17 - distribution: 'temurin' - cache: 'maven' - - - name: Login to GHCR - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: "Build new package" - run: mvn -U -B -V -ntp clean verify - - - name: "Get image tag" - id: image_tag - run: echo "IMAGE_TAG=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout`" >> $GITHUB_OUTPUT - - - name: "Upload Docker images to GHCR" - run: | - docker push ghcr.io/eclipse-pass/deposit-services-core:${{ steps.image_tag.outputs.IMAGE_TAG }} - docker push ghcr.io/eclipse-pass/pass-notification-service:${{ steps.image_tag.outputs.IMAGE_TAG }} - docker push ghcr.io/eclipse-pass/jhu-grant-loader:${{ steps.image_tag.outputs.IMAGE_TAG }} - docker push ghcr.io/eclipse-pass/pass-journal-loader:${{ steps.image_tag.outputs.IMAGE_TAG }} - docker push ghcr.io/eclipse-pass/pass-nihms-loader:${{ steps.image_tag.outputs.IMAGE_TAG }}