From 12e527b3110b6aa8d0a486189f0824074558423d Mon Sep 17 00:00:00 2001 From: Ivan Dimov <78815270+idimov-keeper@users.noreply.github.com> Date: Wed, 6 Sep 2023 14:13:23 -0500 Subject: [PATCH] KSM-461 Added GitHub action to build and release ServiceNow plugin --- .../workflows/publish.servicenow.plugin.yml | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 .github/workflows/publish.servicenow.plugin.yml diff --git a/.github/workflows/publish.servicenow.plugin.yml b/.github/workflows/publish.servicenow.plugin.yml new file mode 100644 index 00000000..51db2ca6 --- /dev/null +++ b/.github/workflows/publish.servicenow.plugin.yml @@ -0,0 +1,115 @@ +name: Release Keeper ServiceNow Plugin + +on: + workflow_dispatch: + inputs: + tagname: + type: string + required: true + description: New tag name for the release + +jobs: + publish-servicenow-plugin: + environment: prod + runs-on: ubuntu-latest + + defaults: + run: + shell: bash + working-directory: ./integration/servicenow-external-credential-resolver + + steps: + - name: Get the source code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + fetch-tags: true + + - name: Validate Release Tag + run: | + TAG="${{ github.event.inputs.tagname }}" + git check-ref-format "tags/${TAG}" && echo "Valid release tag ${TAG}" || echo "Invalid release tag ${TAG}" + git check-ref-format "tags/${TAG}" + + - name: Check if new release tag already exists + run: | + git fetch --tags --quiet + TAG="${{ github.event.inputs.tagname }}" + git show-ref --tags --verify --quiet "refs/tags/${TAG}" && echo "The new release tag already exists" || echo "The new release tag does not exist" + ! git show-ref --tags --verify --quiet "refs/tags/${TAG}" + + - name: Check if version is included in the new release tag + if: ${{ false }} # disable for now + run: | + TAG="${{ github.event.inputs.tagname }}" + GRADLE_CFG=./build.gradle + BUILD_VERSION=`fgrep version $GRADLE_CFG | sed -r 's/^version\s+//g' | sed "s/'//g"` + if [[ "$TAG" == *"-$BUILD_VERSION"* ]]; then + echo "Build version $BUILD_VERSION is included in the tag $TAG" + else + echo "Build version $BUILD_VERSION is not included in the tag $TAG" + exit 1 + fi + + - name: Create Shell Script + run: | + cat <<'EOF' > build.sh + #!/usr/bin/env bash + MID_SERVER_URLS='' + MID_SERVER_URLS=${MID_SERVER_URLS},https://install.service-now.com/glide/distribution/builds/package/mid/2023/08/20/mid.utah-12-21-2022__patch6-08-09-2023_08-20-2023_0545.linux.x86-64.zip + MID_SERVER_URLS=${MID_SERVER_URLS},https://install.service-now.com/glide/distribution/builds/package/mid/2023/06/23/mid.tokyo-07-08-2022__patch9-hotfix2-06-07-2023_06-23-2023_1740.linux.x86-64.zip + MID_SERVER_URLS=${MID_SERVER_URLS},https://install.service-now.com/glide/distribution/builds/package/mid/2023/03/07/mid.sandiego-12-22-2021__patch10-hotfix2-03-06-2023_03-07-2023_0439.linux.x86-64.zip + MID_SERVER_URLS=${MID_SERVER_URLS},https://install.service-now.com/glide/distribution/builds/package/mid/2022/07/21/mid.rome-06-23-2021__patch10-07-13-2022_07-21-2022_1153.linux.x86-64.zip + + releasedir=`pwd`/releases + mkdir -p ${releasedir} + midsdir=`pwd`/mids + mkdir -p ${midsdir} + buildroot=`pwd` + + chmod u+x ${buildroot}/gradlew + gradlecfg=${buildroot}/build.gradle + + buildname=`fgrep archivesName ${gradlecfg} | sed -r 's/^\s*archivesName\s*=\s*//g' | sed "s/'//g"` + buildversion=`fgrep version ${gradlecfg} | sed -r 's/^version\s+//g' | sed "s/'//g"` + srcjarpath=${buildroot}/build/libs/${buildname}-${buildversion}.jar + + IFS="," read -a urls <<< ${MID_SERVER_URLS} + for url in "${urls[@]}"; do + if [[ -n "${url// }" ]] ; then + cd ${midsdir} + filename=${url##*/} + tmp=${url##*/mid.} + version=${tmp%%-*} + + curl -L -O -C - ${url} + unzip -qq -o -d ${midsdir}/${version} ${filename} + + libpath=${midsdir}/${version}/agent/lib + elibpath=${libpath//\//\\/} + sed -i "s/def midserver_agent_dir =.*/def midserver_agent_dir = \'${elibpath}\'/" ${gradlecfg} + + cd ${buildroot} + ./gradlew jar || echo "Build Failed!"; exit 1 + + dstjarpath=${releasedir}/${buildname}-${version}-${buildversion}.jar + mv ${srcjarpath} ${dstjarpath} || echo "File Copy Failed!"; exit 1 + fi + done + EOF + + - name: Run Shell Script + run: | + chmod u+x build.sh + ./build.sh + + - name: Create Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + TAG="${{ github.event.inputs.tagname }}" + GRADLE_CFG=./build.gradle + BUILD_NAME=`fgrep archivesName $GRADLE_CFG | sed -r 's/^\s*archivesName\s*=\s*//g' | sed "s/'//g"` + BUILD_VERSION=`fgrep version $GRADLE_CFG | sed -r 's/^version\s+//g' | sed "s/'//g"` + RELEASE_NAME=${BUILD_NAME}-${BUILD_VERSION}.jar + gh release create ${TAG} `pwd`/releases/*.jar --repo="$GITHUB_REPOSITORY" --title="$RELEASE_NAME" --generate-notes