From 33415195f177e1940da67a74e588bb855a698bab Mon Sep 17 00:00:00 2001 From: skyflow-shravan Date: Tue, 26 Nov 2024 12:38:47 +0530 Subject: [PATCH 1/2] SK-1786 common workflow for internal and public release --- .github/workflows/internal-release.yml | 16 +++ .github/workflows/release.yml | 33 +----- .github/workflows/shared-build-and-deploy.yml | 104 ++++++++++++++++++ pom.xml | 64 +++++++++-- 4 files changed, 178 insertions(+), 39 deletions(-) create mode 100644 .github/workflows/internal-release.yml create mode 100644 .github/workflows/shared-build-and-deploy.yml diff --git a/.github/workflows/internal-release.yml b/.github/workflows/internal-release.yml new file mode 100644 index 00000000..4f3be995 --- /dev/null +++ b/.github/workflows/internal-release.yml @@ -0,0 +1,16 @@ +name: Publish package to the JFROG Artifactory +on: + push: + tags: '*.*.*' + paths-ignore: + - "pom.xml" + - "*.md" + branches: + - release/* + +jobs: + build-and-deploy: + uses: ./.github/workflows/shared-build-and-deploy.yml + with: + ref: ${{ github.ref_name }} + is-internal: true \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 02c7b612..c2fb42d5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,31 +3,8 @@ on: push: tags: '*.*.*' jobs: - publish: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: Set up Maven Central Repository - uses: actions/setup-java@v1 - with: - java-version: '1.8' - distribution: 'adopt' - server-id: ossrh - server-username: MAVEN_USERNAME - server-password: MAVEN_PASSWORD - gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import - gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase - - - name: create-json - id: create-json - uses: jsdaniell/create-json@1.1.2 - with: - name: "credentials.json" - json: ${{ secrets.TEST_CREDENTIALS_FILE_STRING }} - - - name: Publish package to Maven Central - run: mvn --batch-mode deploy - env: - MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} - MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} - MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} \ No newline at end of file + build-and-deploy: + uses: ./.github/workflows/shared-build-and-deploy.yml + with: + ref: ${{ github.ref_name }} + is-internal: false diff --git a/.github/workflows/shared-build-and-deploy.yml b/.github/workflows/shared-build-and-deploy.yml new file mode 100644 index 00000000..9dc71d5e --- /dev/null +++ b/.github/workflows/shared-build-and-deploy.yml @@ -0,0 +1,104 @@ +name: Shared Build and Deploy +on: + workflow_call: + inputs: + ref: + description: 'Git reference to use (e.g., main or branch name)' + required: true + type: string + + is-internal: + description: 'Flag for internal release' + required: true + type: boolean + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ inputs.ref }} + fetch-depth: 0 + + - name: Set up Jfrog artifactory + if: ${{ inputs.is-internal }} + uses: actions/setup-java@v1 + with: + java-version: '1.8' + distribution: 'adopt' + server-id: central + server-username: JFROG_USERNAME + server-password: JFROG_PASSWORD + gpg-private-key: ${{ secrets.JFROG_GPG_KEY }} # Value of the GPG private key to import + gpg-passphrase: JFROG_GPG_PASSPHRASE # env variable for GPG private key passphrase + + - name: Set up Maven Central Repository + if: ${{ !inputs.is-internal }} + uses: actions/setup-java@v1 + with: + java-version: '1.8' + distribution: 'adopt' + server-id: ossrh + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import + gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase + + - name: Get Previous tag + id: previoustag + uses: WyriHaximus/github-action-get-previous-tag@v1 + with: + fallback: 1.0.0 + + - name: Bump Version + run: | + chmod +x ./ci-scripts/bump_version.sh + if ${{ inputs.is-internal }}; then + ./ci-scripts/bump_version.sh "${{ steps.previoustag.outputs.tag }}" "$(git rev-parse --short "$GITHUB_SHA")" + else + ./ci-scripts/bump_version.sh "${{ steps.previoustag.outputs.tag }}" + fi + + - name: Commit changes + run: | + git config user.name ${{ github.actor }} + git config user.email ${{ github.actor }}@users.noreply.github.com + git add pom.xml + if ${{ inputs.is-internal }}; then + git commit -m "[AUTOMATED] Private Release ${{ steps.previoustag.outputs.tag }}-dev-$(git rev-parse --short $GITHUB_SHA)" + git push origin ${{ github.ref_name }} -f + else + git commit -m "[AUTOMATED] Public Release - ${{ steps.previoustag.outputs.tag }}" + git push origin + + - name: Create env + if: ${{ inputs.is-internal }} + id: create-env + run: | + touch .env + echo SKYFLOW_CREDENTIALS=${{ secrets.SKYFLOW_CREDENTIALS }} >> .env + echo TEST_EXPIRED_TOKEN=${{ secrets.TEST_EXPIRED_TOKEN }} >> .env + + - name: Create credentials json + id: create-json + uses: jsdaniell/create-json@1.1.2 + with: + name: "credentials.json" + json: ${{ secrets.TEST_CREDENTIALS_FILE_STRING }} + + - name: Publish package to Jfrog Artifactory + if: ${{ inputs.is-internal }} + run: mvn clean deploy -P jfrog + env: + JFROG_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }} + JFROG_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }} + JFROG_GPG_PASSPHRASE: ${{ secrets.JFROG_GPG_PASSPHRASE }} + + - name: Publish package to Maven Central + if: ${{ !inputs.is-internal }} + run: mvn --batch-mode deploy -P maven-central + env: + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} + MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 1b5060b0..28a2cca9 100644 --- a/pom.xml +++ b/pom.xml @@ -107,17 +107,6 @@ - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.7 - true - - ossrh - https://s01.oss.sonatype.org/ - true - - org.apache.maven.plugins maven-source-plugin @@ -197,5 +186,58 @@ + + + maven_central + Maven Central + https://repo.maven.apache.org/maven2/ + + + + + + maven-central + + + ossrh + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2 + + + ossrh + https://s01.oss.sonatype.org/content/repositories/snapshots + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrh + https://s01.oss.sonatype.org/ + true + + + + + + + jfrog + + + central + prekarilabs.jfrog.io-releases + https://prekarilabs.jfrog.io/artifactory/skyflow-java + + + snapshots + prekarilabs.jfrog.io-snapshots + https://prekarilabs.jfrog.io/artifactory/skyflow-java + + + + \ No newline at end of file From 9878f5c1cc6440480a77433445cb81f0851778a2 Mon Sep 17 00:00:00 2001 From: skyflow-shravan Date: Tue, 26 Nov 2024 22:34:16 +0530 Subject: [PATCH 2/2] SK-1786 common workflow for internal and public release --- .github/workflows/internal-release.yml | 9 ++- .github/workflows/pr.yml | 2 +- .github/workflows/release.yml | 7 ++ .github/workflows/shared-build-and-deploy.yml | 73 ++++++++++--------- pom.xml | 7 -- scripts/bump_version.sh | 40 ++++++++++ 6 files changed, 93 insertions(+), 45 deletions(-) create mode 100644 scripts/bump_version.sh diff --git a/.github/workflows/internal-release.yml b/.github/workflows/internal-release.yml index 4f3be995..1e26a801 100644 --- a/.github/workflows/internal-release.yml +++ b/.github/workflows/internal-release.yml @@ -13,4 +13,11 @@ jobs: uses: ./.github/workflows/shared-build-and-deploy.yml with: ref: ${{ github.ref_name }} - is-internal: true \ No newline at end of file + is-internal: true + server-id: central + profile: jfrog + secrets: + server-username: ${{ secrets.ARTIFACTORY_USERNAME }} + server-password: ${{ secrets.ARTIFACTORY_PASSWORD }} + gpg-key: ${{ secrets.JFROG_GPG_KEY }} + gpg-passphrase: ${{ secrets.JFROG_GPG_PASSPHRASE }} \ No newline at end of file diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index c3a33dc8..7ce64698 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -10,7 +10,7 @@ jobs: - name: Check JIRA ID uses: gsactions/commit-message-checker@v1 with: - pattern: '\[?[A-Z]{1,5}-[1-9][0-9]*.+$' + pattern: '(\[?[A-Z]{1,5}-[1-9][0-9]*)|(\[AUTOMATED\])|(Merge)|(Release).+$' flags: 'gm' excludeDescription: 'true' checkAllCommitMessages: 'true' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c2fb42d5..f978c067 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,3 +8,10 @@ jobs: with: ref: ${{ github.ref_name }} is-internal: false + server-id: ossrh + profile: maven-central + secrets: + server-username: ${{ secrets.OSSRH_USERNAME }} + server-password: ${{ secrets.OSSRH_PASSWORD }} + gpg-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} + gpg-passphrase: ${{ secrets.MAVEN_GPG_PASSPHRASE }} \ No newline at end of file diff --git a/.github/workflows/shared-build-and-deploy.yml b/.github/workflows/shared-build-and-deploy.yml index 9dc71d5e..43a54dec 100644 --- a/.github/workflows/shared-build-and-deploy.yml +++ b/.github/workflows/shared-build-and-deploy.yml @@ -12,6 +12,28 @@ on: required: true type: boolean + server-id: + description: 'Id of the repository' + required: true + type: string + + profile: + description: 'Profile to pick from pom.xml' + required: true + type: string + secrets: + server-username: + required: true + + server-password: + required: true + + gpg-key: + required: true + + gpg-passphrase: + required: true + jobs: publish: runs-on: ubuntu-latest @@ -21,29 +43,16 @@ jobs: ref: ${{ inputs.ref }} fetch-depth: 0 - - name: Set up Jfrog artifactory - if: ${{ inputs.is-internal }} + - name: Set up maven or jfrog repository uses: actions/setup-java@v1 with: java-version: '1.8' distribution: 'adopt' - server-id: central - server-username: JFROG_USERNAME - server-password: JFROG_PASSWORD - gpg-private-key: ${{ secrets.JFROG_GPG_KEY }} # Value of the GPG private key to import - gpg-passphrase: JFROG_GPG_PASSPHRASE # env variable for GPG private key passphrase - - - name: Set up Maven Central Repository - if: ${{ !inputs.is-internal }} - uses: actions/setup-java@v1 - with: - java-version: '1.8' - distribution: 'adopt' - server-id: ossrh - server-username: MAVEN_USERNAME - server-password: MAVEN_PASSWORD - gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import - gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase + server-id: ${{ inputs.server-id }} + server-username: SERVER_USERNAME + server-password: SERVER_PASSWORD + gpg-private-key: ${{ secrets.gpg-key }} # Value of the GPG private key to import + gpg-passphrase: GPG_PASSPHRASE # env variable for GPG private key passphrase - name: Get Previous tag id: previoustag @@ -53,11 +62,11 @@ jobs: - name: Bump Version run: | - chmod +x ./ci-scripts/bump_version.sh + chmod +x ./scripts/bump_version.sh if ${{ inputs.is-internal }}; then - ./ci-scripts/bump_version.sh "${{ steps.previoustag.outputs.tag }}" "$(git rev-parse --short "$GITHUB_SHA")" + ./scripts/bump_version.sh "${{ steps.previoustag.outputs.tag }}" "$(git rev-parse --short "$GITHUB_SHA")" else - ./ci-scripts/bump_version.sh "${{ steps.previoustag.outputs.tag }}" + ./scripts/bump_version.sh "${{ steps.previoustag.outputs.tag }}" fi - name: Commit changes @@ -71,6 +80,7 @@ jobs: else git commit -m "[AUTOMATED] Public Release - ${{ steps.previoustag.outputs.tag }}" git push origin + fi - name: Create env if: ${{ inputs.is-internal }} @@ -87,18 +97,9 @@ jobs: name: "credentials.json" json: ${{ secrets.TEST_CREDENTIALS_FILE_STRING }} - - name: Publish package to Jfrog Artifactory - if: ${{ inputs.is-internal }} - run: mvn clean deploy -P jfrog - env: - JFROG_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }} - JFROG_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }} - JFROG_GPG_PASSPHRASE: ${{ secrets.JFROG_GPG_PASSPHRASE }} - - - name: Publish package to Maven Central - if: ${{ !inputs.is-internal }} - run: mvn --batch-mode deploy -P maven-central + - name: Publish package + run: mvn clean deploy -P ${{ inputs.profile }} env: - MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} - MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} - MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} \ No newline at end of file + SERVER_USERNAME: ${{ secrets.server-username }} + SERVER_PASSWORD: ${{ secrets.server-password }} + GPG_PASSPHRASE: ${{ secrets.gpg-passphrase }} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 28a2cca9..87e2d899 100644 --- a/pom.xml +++ b/pom.xml @@ -186,13 +186,6 @@ - - - maven_central - Maven Central - https://repo.maven.apache.org/maven2/ - - diff --git a/scripts/bump_version.sh b/scripts/bump_version.sh new file mode 100644 index 00000000..008cae3f --- /dev/null +++ b/scripts/bump_version.sh @@ -0,0 +1,40 @@ +# Input Arguments +Version=$1 +CommitHash=$2 +PomFile="$GITHUB_WORKSPACE/pom.xml" + +if [ -z "$Version" ]; then + echo "Error: Version argument is required." + exit 1 +fi + +# Update only the main project's +if [ -z "$CommitHash" ]; then + echo "Bumping main project version to $Version" + + awk -v version="$Version" ' + BEGIN { updated = 0 } + // && updated == 0 { + sub(/.*<\/version>/, "" version "") + updated = 1 + } + { print } + ' "$PomFile" > tempfile && cat tempfile > "$PomFile" && rm -f tempfile + + echo "--------------------------" + echo "Done. Main project version now at $Version" +else + echo "Bumping main project version to $Version-dev-$CommitHash" + + awk -v version="$Version-dev.$CommitHash" ' + BEGIN { updated = 0 } + // && updated == 0 { + sub(/.*<\/version>/, "" version "") + updated = 1 + } + { print } + ' "$PomFile" > tempfile && cat tempfile > "$PomFile" && rm -f tempfile + + echo "--------------------------" + echo "Done. Main project version now at $Version-dev.$CommitHash" +fi \ No newline at end of file