From 81d423fd24701de33f2f69756c3205b83b034301 Mon Sep 17 00:00:00 2001 From: Your GitHub Username Date: Fri, 22 Sep 2023 16:08:33 +0530 Subject: [PATCH] build: updated vendor title and added release workflow --- .github/workflows/CHANGELOG.tpl.md | 4 + .github/workflows/release.yml | 217 +++++++++++++++++++++++++++++ CHANGELOG.md | 9 ++ README.md | 3 +- build.gradle | 12 +- r2dbc-proxy/build.gradle | 8 +- 6 files changed, 241 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/CHANGELOG.tpl.md create mode 100644 .github/workflows/release.yml create mode 100644 CHANGELOG.md diff --git a/.github/workflows/CHANGELOG.tpl.md b/.github/workflows/CHANGELOG.tpl.md new file mode 100644 index 0000000..19184ac --- /dev/null +++ b/.github/workflows/CHANGELOG.tpl.md @@ -0,0 +1,4 @@ + +{{.SECTION}}### $title{{.SECTION}} +{{.COMMITS}}- $commit{{.COMMITS}} + diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..62dee4a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,217 @@ +name: Build and Release (Manual Run) v1.3 + +on: + workflow_dispatch: # This event allows manual triggering + +jobs: + build-and-release: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + + - name: Set up JDK 8 + uses: actions/setup-java@v3 + with: + java-version: 8 + distribution: 'temurin' + + + - name: Set Extensions Dir + id: set_ext_dir + run: | + echo "Setting Extensions Dir..." + mkdir ${HOME}/release + mkdir /tmp/to + echo "NEW_RELIC_EXTENSIONS_DIR=${HOME}/release" >> $GITHUB_ENV + + - name: Build with Gradle and verifyInstrumentation + run: | + . ./newrelic-dependencies.sh + ./gradlew clean build install verifyInstrumentation + + - name: Identify Release Type + id: define_release_type + run: | + echo "Generating changelog to check type of release..." + old_tag=$(git describe --abbrev=0 --tags 2>/dev/null) || true + if [[ -n "$old_tag" ]]; then + changelog=$(git log --pretty=format:"- %s (%h)" $old_tag..HEAD) + fi + if echo "$changelog" | grep -iqE '\bBREAKING CHANGE\b'; then + echo "RELEASE_TYPE=major" >> $GITHUB_ENV + elif echo "$changelog" | grep -iqE '\bfeat\b'; then + echo "RELEASE_TYPE=minor" >> $GITHUB_ENV + else + echo "RELEASE_TYPE=patch" >> $GITHUB_ENV + fi + + - name: Set release version + id: set_release_version + run: | + major_version=1 + minor_version=0 + patch_revision=1 + + # Retrieve the latest release tag + latest_tag=$(git describe --abbrev=0 --tags 2>/dev/null) || true + echo "LATEST_TAG=${latest_tag}" >> $GITHUB_ENV + + if [[ -n "$latest_tag" && $latest_tag == v* ]]; then + # Extract the major and minor versions from the latest tag + current_major_version=$(echo $latest_tag | cut -d'.' -f1 | sed 's/v//') + current_minor_version=$(echo $latest_tag | cut -d'.' -f2) + current_patch_revision=$(echo $latest_tag | cut -d'.' -f3) + + if [ "${{ env.RELEASE_TYPE }}" = "major" ]; then + major_version=$((current_major_version +1 )) + elif [ "${{ env.RELEASE_TYPE }}" = "minor" ]; then + minor_version=$((current_minor_version + 1)) + major_version=$((current_major_version)) + else + patch_revision=$((current_patch_revision + 1)) + minor_version=$((current_minor_version)) + major_version=$((current_major_version)) + fi + + fi + + # Set the release version environment variable + release_version="v${major_version}.${minor_version}.${patch_revision}" + echo "RELEASE_VERSION=${release_version}" >> $GITHUB_ENV + + - name: Set Tag + id: set_tag + run: echo "::set-output name=tag::${{ env.RELEASE_VERSION }}" + + - name: Set release name + id: set_release_name + run: | + repo_name="${{ github.repository }}" + sanitized_repo_name=$(echo "$repo_name" | awk -F 'newrelic-java-' '{print $2}') + echo "RELEASE_NAME=${sanitized_repo_name}-instrumentation-" >> $GITHUB_ENV + previous_tag=$(git describe --abbrev=0 --tags HEAD^ 2>/dev/null || git rev-list --max-parents=0 HEAD) + + - name: Create Archive + run: | + echo "CURRENT=${PWD}" >> $GITHUB_ENV + cd ${HOME}/release + zip -r /tmp/to/${{ env.RELEASE_NAME}}${{ steps.set_tag.outputs.tag }}.zip *.jar + cd ${{env.CURRENT}} + + + + - name: Create Release + id: create_release + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + try { + var changelog = ``; + var tag = '' + `${{ steps.set_tag.outputs.tag }}`; + const archivePath = '/tmp/to/${{ env.RELEASE_NAME}}${{ steps.set_tag.outputs.tag }}.zip'; + var response = await github.rest.repos.createRelease({ + draft:false, + generate_release_notes:true, + name:tag, + owner:context.repo.owner, + prerelease:false, + repo:context.repo.repo, + tag_name:tag, + body:changelog + }); + + core.exportVariable('RELEASE_ID', response.data.id); + core.exportVariable('RELEASE_URL', response.data.html_url); + core.exportVariable('RELEASE_UPLOAD_URL', response.data.upload_url); + } catch (error) { + core.setFailed(error.message); + } + - name: Upload Release Artifacts + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + asset_path: /tmp/to/${{ env.RELEASE_NAME}}${{ steps.set_tag.outputs.tag }}.zip + asset_name: ${{ env.RELEASE_NAME}}${{ steps.set_tag.outputs.tag }}.zip + upload_url: ${{ env.RELEASE_UPLOAD_URL }} + asset_content_type: application/zip + + - name: "Generate release changelog" + id: github_changelog + uses: Helmisek/conventional-changelog-generator@v1.0.6-release + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + commit-types: "fix:Bug Fixes,feat:Features,doc:Documentation,build:Build Upgrades,BREAKING CHANGE:Enhancements" + template-path: ".github/workflows/CHANGELOG.tpl.md" + + + - name: update CHANGELOG.md + run: | + # Content to add at the top + # Get the current date in YYYY-MM-DD format + release_date=$(date +"%Y-%m-%d") + version="## Version: [${{env.RELEASE_VERSION}}](${{ env.RELEASE_URL }}) | Created: $release_date" + content="$version${{steps.github_changelog.outputs.changelog}}" + + # Existing file + file="CHANGELOG.md" + + # Create a temporary file with the content at the top and existing content below + + echo "$content" > temp_file.txt + cat "$file" >> temp_file.txt + + # Overwrite the original file with the updated content + mv temp_file.txt "$file" + + # Commit the updated CHANGELOG.md file + git add CHANGELOG.md + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git commit -m "Update Changelog for Release [skip ci]" + + # Push the changes to the remote repository + git push --quiet --set-upstream origin HEAD + + - name: Get Compare URL + run: | + compare=$(echo ${{ env.RELEASE_URL }} | sed 's/releases\/tag.*/compare/') + compareurl=$(echo "\nFull Changelog: ($compare/${{ env.LATEST_TAG }}...${{ steps.set_tag.outputs.tag }})") + echo "COMPAREURL=${compareurl}" >> $GITHUB_ENV + + - name: Update Release + id: update_release + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + try { + + + var changelog = `${{steps.github_changelog.outputs.changelog}}` + `${{env.COMPAREURL}}` ; + var release_id = `${{env.RELEASE_ID}}`; + var tag = '' + `${{ steps.set_tag.outputs.tag }}`; + const archivePath = '/tmp/to/${{ env.RELEASE_NAME}}${{ steps.set_tag.outputs.tag }}.zip'; + var _response = await github.rest.repos.updateRelease({ + draft:false, + generate_release_notes:true, + owner:context.repo.owner, + repo: context.repo.repo, + prerelease:false, + release_id:release_id, + body:changelog + }); + + core.exportVariable('RELEASE_ID', _response.data.id); + core.exportVariable('RELEASE_URL', _response.data.html_url); + core.exportVariable('RELEASE_UPLOAD_URL', _response.data.upload_url); + } catch (error) { + core.setFailed(error.message); + } + diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..a9f1e20 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +## Installation + +To install: + +1. Download the latest release jar files. +2. In the New Relic Java directory (the one containing newrelic.jar), create a directory named extensions if it does not already exist. +3. Copy the downloaded jars into the extensions directory. +4. Restart the application. + diff --git a/README.md b/README.md index 09a71cb..5aeb662 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -[![New Relic Experimental header](https://github.com/newrelic/opensource-website/raw/master/src/images/categories/Experimental.png)](https://opensource.newrelic.com/oss-category/#new-relic-experimental) - +New Relic Open Source experimental project banner. ![GitHub forks](https://img.shields.io/github/forks/newrelic-experimental/newrelic-java-r2dbc?style=social) ![GitHub stars](https://img.shields.io/github/stars/newrelic-experimental/newrelic-java-r2dbc?style=social) diff --git a/build.gradle b/build.gradle index 0a78aa1..7a570bd 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ plugins { } project.ext { - group = 'com.newrelic.instrumentation' + group = 'com.newrelic.instrumentation.labs' javaAgentVersion = '6.4.0' // Aligned with minimum Java major version supported by latest Java Agent @@ -76,7 +76,7 @@ task buildIfNeeded { task createModule { dependsOn checkForDependencies description = 'Generate project files for a new instrumentation module' - group = 'New Relic' + group = 'New Relic Labs' doLast { def rootProject = projectDir.path @@ -119,7 +119,7 @@ task createModule { // Example: // implementation 'javax.servlet:servlet-api:2.5' - // New Relic Java Agent dependencies + // New Relic Labs Java Agent dependencies implementation 'com.newrelic.agent.java:newrelic-agent:JAVA_AGENT_VERSION' implementation 'com.newrelic.agent.java:newrelic-api:JAVA_AGENT_VERSION' implementation fileTree(include: ['*.jar'], dir: '../libs') @@ -129,8 +129,8 @@ task createModule { jar { manifest { attributes 'Implementation-Title': 'PROJECT_GROUP.PROJECT_NAME' - attributes 'Implementation-Vendor': 'New Relic' - attributes 'Implementation-Vendor-Id': 'com.newrelic' + attributes 'Implementation-Vendor': 'New Relic Labs' + attributes 'Implementation-Vendor-Id': 'com.newrelic.labs' attributes 'Implementation-Version': 1.0 } } @@ -175,7 +175,7 @@ subprojects { task install(dependsOn: buildIfNeeded, type: Copy) { description = 'Copies compiled jar to the NEW_RELIC_EXTENSIONS_DIR.' - group = 'New Relic' + group = 'New Relic Labs' def extDir = System.getenv("NEW_RELIC_EXTENSIONS_DIR") ?: " " diff --git a/r2dbc-proxy/build.gradle b/r2dbc-proxy/build.gradle index f5205af..e5e449f 100644 --- a/r2dbc-proxy/build.gradle +++ b/r2dbc-proxy/build.gradle @@ -6,7 +6,7 @@ apply plugin: 'java' dependencies { implementation 'io.r2dbc:r2dbc-proxy:0.8.4.RELEASE' - // New Relic Java Agent dependencies + // New Relic Labs Java Agent dependencies implementation 'com.newrelic.agent.java:newrelic-agent:6.4.0' implementation 'com.newrelic.agent.java:newrelic-api:6.4.0' implementation fileTree(include: ['*.jar'], dir: '../libs') @@ -15,9 +15,9 @@ dependencies { jar { manifest { - attributes 'Implementation-Title': 'com.newrelic.instrumentation.r2dbc-proxy' - attributes 'Implementation-Vendor': 'New Relic' - attributes 'Implementation-Vendor-Id': 'com.newrelic' + attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.r2dbc-proxy' + attributes 'Implementation-Vendor': 'New Relic Labs' + attributes 'Implementation-Vendor-Id': 'com.newrelic.labs' attributes 'Implementation-Version': 1.0 } }