From 412b1855ab05c617fa4bb97aa6f037c7d92b3270 Mon Sep 17 00:00:00 2001 From: cleverchuk Date: Tue, 2 Jul 2024 09:57:43 -0400 Subject: [PATCH] NH-37575: download agent from GitHub --- .github/workflows/push.yml | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index d4d301dc..932b8b5f 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -24,6 +24,60 @@ env: STAGE_BUCKET: ${{ secrets.STAGE_BUCKET }} jobs: + github_release: + if: inputs.run_github_release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: Build agent + run: ./gradlew clean build -x test + + - name: Pre-release and upload artifacts + run: | + VERSION=$(unzip -p agent/build/libs/solarwinds-apm-agent.jar META-INF/MANIFEST.MF | grep Implementation-Version | awk '{ print $2 }') + VERSION=$(echo $VERSION | sed 's/[^a-z0-9.-]//g') # remove illegal characters + VERSION="$VERSION-alpha" + echo "Current version is $VERSION" + + response=$(curl -fs -L \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${GITHUB_TOKEN}"\ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/$GITHUB_REPOSITORY/releases \ + -d '{"tag_name":"v'"$VERSION"'", "name":"v'"$VERSION"'", "body":"New release: v'"$VERSION"'", "draft":false, "prerelease":true}') + + release_id=$(echo "$response" | jq -r '.id') + + # Function to upload a file to GitHub release + upload_file_to_release() { + local release_id="$1" + local file_path="$2" + + # Extract filename from file path + file_name=$(basename "$file_path") + + # Upload file to GitHub release + curl -fs \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $GITHUB_TOKEN" \ + -H "Content-Type: application/octet-stream" \ + --data-binary @"$file_path" \ + "https://uploads.github.com/repos/$GITHUB_REPOSITORY/releases/$release_id/assets?name=$file_name" + } + + # Upload file to GitHub release + upload_file_to_release "$release_id" "agent/build/libs/solarwinds-apm-agent.jar" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + s3-stage-upload: # this job uploads the jar to stage s3 runs-on: ubuntu-latest steps: