Create version bump PR #86
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Create version bump PR | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Next Version Number (x.y.zzz).' | |
required: true | |
tracer_version: | |
description: 'Next Version Number (x.y.z). To be used for a tracer version bump.' | |
required: false | |
update_agent: | |
description: 'Update the agent as well' | |
type: boolean | |
required: false | |
default: false | |
repository_dispatch: | |
types: [dd-trace-dotnet-release] | |
jobs: | |
bump_version: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write # Creates a branch | |
pull-requests: write # Creates a PR | |
actions: read # read secrets | |
env: | |
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | |
steps: | |
- name: "Set Variables" | |
id: "set_variables" | |
run: | | |
if [[ ! -z "${{ github.event.inputs.version }}" ]]; then | |
echo "::set-output name=version::${{ github.event.inputs.version }}" | |
echo "::set-output name=tracer_version::${{ github.event.inputs.tracer_version }}" | |
elif [[ ! -z "${{ github.event.client_payload.version }}" ]]; then | |
TRACERVERSION=${{ github.event.client_payload.version }} | |
echo "Version received from dd-trace-dotnet: $TRACERVERSION" | |
TRACERVERSION=${TRACERVERSION:1} | |
echo "Version received once normalized: $TRACERVERSION" | |
echo "::set-output name=version::${TRACERVERSION}00" | |
echo "::set-output name=tracer_version::$TRACERVERSION" | |
else | |
echo "Error. Versions weren't provided in input." | |
exit 1 | |
fi | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: "Get last agent release" | |
id: last_release | |
uses: pozetroninc/github-action-get-latest-release@master | |
with: | |
owner: DataDog | |
repo: datadog-agent | |
excludes: prerelease, draft | |
- name: "Modify build-packages" | |
id: "versions" | |
run: | | |
versionRegex="[0-9]*.[0-9]*.[0-9]*" | |
splitVersionRegex="([0-9]+).([0-9]+).([0-9]+)" | |
CURRENTVERSION="$(grep -o -e RELEASE_VERSION\=\"$versionRegex dotnet/build-packages.sh | sed 's/RELEASE_VERSION="//')" | |
echo Current version is: $CURRENTVERSION | |
VERSION=${{ steps.set_variables.outputs.version }} | |
echo Bumping extension version to $VERSION | |
sed -i -e "s/RELEASE_VERSION=\"$CURRENTVERSION\"/RELEASE_VERSION=\"$VERSION\"/g" dotnet/build-packages.sh | |
echo Replaced release version in file. | |
PR_BODY="Bumps the release version to $VERSION" | |
TRACER_VERSION=${{steps.set_variables.outputs.tracer_version}} | |
if [ -n "$TRACER_VERSION" ]; then | |
CURRENT_TRACER_VERSION="$(grep -o -e dd-trace-dotnet/releases/download/v$versionRegex dotnet/build-packages.sh | sed 's#dd-trace-dotnet/releases/download/v##')" | |
echo Current tracer version is: $CURRENT_TRACER_VERSION | |
echo Bumping tracer version to $TRACER_VERSION | |
sed -i -e "s#dd-trace-dotnet/releases/download/v$CURRENT_TRACER_VERSION#dd-trace-dotnet/releases/download/v$TRACER_VERSION#" dotnet/build-packages.sh | |
echo Replaced release version in file. | |
PR_BODY="$PR_BODY, updates the tracer version to: $TRACER_VERSION " | |
fi | |
if [ "${{ github.event.inputs.update_agent }}" == "true" ]; then | |
CURRENT_AGENT_VERSION="$(grep -o -e agent-binaries-$versionRegex dotnet/build-packages.sh | sed 's/agent-binaries-//')" | |
AGENT_VERSION=${{ steps.last_release.outputs.release }} | |
echo Current agent version is: $CURRENT_AGENT_VERSION | |
echo "Latest Agent version: $AGENT_VERSION" | |
major=0 | |
minor=0 | |
build=0 | |
agent_major=0 | |
agent_minor=0 | |
agent_build=0 | |
if [[ $CURRENT_AGENT_VERSION =~ $splitVersionRegex ]]; then | |
major="${BASH_REMATCH[1]}" | |
minor="${BASH_REMATCH[2]}" | |
build="${BASH_REMATCH[3]}" | |
fi | |
if [[ $AGENT_VERSION =~ $splitVersionRegex ]]; then | |
agent_major="${BASH_REMATCH[1]}" | |
agent_minor="${BASH_REMATCH[2]}" | |
agent_build="${BASH_REMATCH[3]}" | |
fi | |
if [[ $agent_major > $major ]]; then | |
newAgentAvailable=1 | |
elif [[ $agent_minor > $minor ]]; then | |
newAgentAvailable=1 | |
elif [[ $agent_build > $build ]]; then | |
newAgentAvailable=1 | |
fi | |
if [[ "$newAgentAvailable" == "1" ]]; then | |
echo Updating agent version | |
sed -i -e "s/agent-binaries-$CURRENT_AGENT_VERSION/agent-binaries-$AGENT_VERSION/" dotnet/build-packages.sh | |
sed -i -e "s/agent-binaries-$CURRENT_AGENT_VERSION/agent-binaries-$AGENT_VERSION/" dotnet/build-packages-dev.sh | |
echo Replaced agent version in file. | |
PR_BODY="$PR_BODY, and updates the agent version to: $AGENT_VERSION" | |
fi | |
fi | |
PR_BODY="$PR_BODY." | |
echo "::set-output name=version::$VERSION" | |
echo "::set-output name=tracer_version::$TRACER_VERSION" | |
echo "::set-output name=pr_body::$PR_BODY" | |
- name: Create Pull Request | |
id: pr | |
uses: peter-evans/[email protected] | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
branch: "version-bump-${{steps.versions.outputs.version}}" | |
commit-message: "[.Net Version Bump] Bump to v${{steps.versions.outputs.version}}" | |
delete-branch: true | |
title: "[.Net Version Bump] Bump to v${{steps.versions.outputs.version}}" | |
body: "${{steps.versions.outputs.pr_body}}" | |
- name: Display output | |
run: | | |
echo "Pull Request Number - ${{ steps.pr.outputs.pull-request-number }}" | |
echo "Pull Request URL - ${{ steps.pr.outputs.pull-request-url }}" |