From bc1c9269976a747401471d02ecb71d42f4d91c04 Mon Sep 17 00:00:00 2001 From: Xavier Schildwachter Date: Wed, 11 Sep 2024 08:54:29 -0700 Subject: [PATCH] SWC-6663: build and publish SWC artifact from GH (#5513) * CI * Fix cond * Fix cond * Fix * Fix syntax * Actual * Invert logic to test * Test * Test * Reset test * Test * Fix e2e * Merge changes into existing infra * Add release branch workflow * Fixes from POC * Pass creds * Typo --- .github/workflows/build-test-e2e.yml | 2 + .github/workflows/build/action.yml | 20 +++++++++- .github/workflows/main.yaml | 41 ++++++++++++++++++++ .github/workflows/maven.yml | 19 ---------- .github/workflows/release.yaml | 56 ++++++++++++++++++++++++++++ 5 files changed, 118 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/main.yaml delete mode 100644 .github/workflows/maven.yml create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/build-test-e2e.yml b/.github/workflows/build-test-e2e.yml index 1575bc86e0..d1f4c82bc9 100644 --- a/.github/workflows/build-test-e2e.yml +++ b/.github/workflows/build-test-e2e.yml @@ -31,6 +31,8 @@ jobs: - uses: actions/checkout@v3 - name: Build SWC uses: ./.github/workflows/build + with: + mvn_goal: package - name: Upload build to GitHub Actions Artifacts uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/build/action.yml b/.github/workflows/build/action.yml index af3ae01f4c..a0c80465cd 100644 --- a/.github/workflows/build/action.yml +++ b/.github/workflows/build/action.yml @@ -1,5 +1,13 @@ name: 'Build SWC' description: 'Build SWC' +inputs: + mvn_goal: + description: the goal that maven needs to run + required: true + pom_version: + description: the version for the generated artifact + required: false + default: '' runs: using: 'composite' steps: @@ -9,6 +17,16 @@ runs: java-version: '11' distribution: 'corretto' cache: maven + server-id: sagebionetworks + server-username: ${{ env.MAVEN_USERNAME }} + server-password: ${{ env.MAVEN_USERPWD }} + + - name: Version pom.xml + shell: bash + run: | + if [ "${{ inputs.pom_version }}" != "" ]; then + mvn versions:set -DnewVersion=${{ inputs.pom_version }} + fi - name: Build with Maven shell: bash - run: mvn -B package --file pom.xml + run: mvn -B ${{ inputs.mvn_goal }} --file pom.xml diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000000..01881a9c33 --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,41 @@ +name: build-main + +on: + push: + branches: [develop, release-**] + pull_request: + branches: [develop, release-**] + +jobs: + call-build: + runs-on: ubuntu-latest + if: ${{ github.event_name == 'push' }} + steps: + - uses: actions/checkout@v4 + with: + fetch-tags: true + fetch-depth: 0 + + - name: Set POM version for dev branch + if: ${{ github.ref == 'refs/heads/develop' }} + run: echo "pomversion=$(date +%Y-%m-%d)-$(git rev-parse --short HEAD)" >> $GITHUB_ENV + - name: Set POM version for release branch + if: ${{ startsWith(github.ref, 'refs/heads/release-') }} + run: echo "pomversion=$(date +%Y-%m-%d)-$(git describe --tags)" >> $GITHUB_ENV + + - uses: ./.github/workflows/build + with: + mvn_goal: package + pom_version: ${{ env.pomversion }} + env: + MAVEN_USERNAME: ${{ secrets.PLATFORM_ARTIFACTORY_USER }} + MAVEN_USERPWD: ${{ secrets.PLATFORM_ARTIFACTORY_PWD }} + + call-test: + runs-on: ubuntu-latest + if: ${{ github.event_name == 'pull_request' }} + steps: + - uses: actions/checkout@v4 + - uses: ./.github/workflows/build + with: + mvn_goal: test diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml deleted file mode 100644 index 4763d93659..0000000000 --- a/.github/workflows/maven.yml +++ /dev/null @@ -1,19 +0,0 @@ -# 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://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven - -name: Java CI with Maven - -on: - pull_request: - branches: [develop, release-**] - push: - branches: [develop] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Build SWC - uses: ./.github/workflows/build diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000000..b03b288c38 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,56 @@ +name: release + +on: + workflow_dispatch: + +jobs: + release: + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} + fetch-depth: 0 + + - id: extract_release + run: | + branch_name="${GITHUB_REF#refs/heads/}" + if [[ $branch_name =~ ^release-([0-9]+)$ ]]; then + release_number=${BASH_REMATCH[1]} + echo "release_number=$release_number" >> $GITHUB_ENV + else + echo "Invalid branch name format" + exit 1 + fi + + - id: git_config + run: | + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + + - id: push_prod_tag + run: | + tag_name="${release_number}.1" + git tag -a $tag_name -m stack-${release_number}-prod + git push origin $tag_name + + - id: create_new_release_branch + run: | + git checkout develop + next_release_number=$((release_number + 1)) + new_branch="release-${next_release_number}" + git checkout -b $new_branch + + new_tag="${next_release_number}.0" + git tag -a $new_tag -m stack-${next_release_number}-staging + git push origin $new_branch + echo "pomversion=$new_tag" >> $GITHUB_ENV + + - id: build_new_release_branch + uses: ./.github/workflows/build + with: + mvn_goal: package + pom_version: ${{ env.pomversion }}