From 4b648ee8433873eae3c2a9550f754d16b8b87cfa Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Tue, 21 Feb 2023 11:55:38 +0100 Subject: [PATCH] Release workflow --- .github/workflows/lib-injection.yml | 3 +- .github/workflows/release-lib-injection.yml | 33 +++++++++++++++++++++ lib-injection/auto_inject.rb | 20 ++++++++----- 3 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/release-lib-injection.yml diff --git a/.github/workflows/lib-injection.yml b/.github/workflows/lib-injection.yml index 1b8804884c9..e1e78e861e7 100644 --- a/.github/workflows/lib-injection.yml +++ b/.github/workflows/lib-injection.yml @@ -6,7 +6,7 @@ on: jobs: build-and-publish-test-image: runs-on: ubuntu-latest - steps: + steps: - uses: actions/checkout@v3 - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -23,3 +23,4 @@ jobs: platforms: 'linux/amd64,linux/arm64/v8' build-args: DDTRACE_RUBY_SHA=${{ github.sha }} context: ./lib-injection + diff --git a/.github/workflows/release-lib-injection.yml b/.github/workflows/release-lib-injection.yml new file mode 100644 index 00000000000..43d3708d166 --- /dev/null +++ b/.github/workflows/release-lib-injection.yml @@ -0,0 +1,33 @@ + +name: "Release Library Injection" +on: + push: + tags: + - 'v*.*.*' + +jobs: + build-and-publish-release-image: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set version + id: version + run: echo "version=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT + - name: Get version + run: echo "The selected version is ${{ steps.version.outputs.version }}" + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + - name: Login to Docker + run: docker login -u publisher -p ${{ secrets.GITHUB_TOKEN }} ghcr.io + - name: Docker Build + uses: docker/build-push-action@v3 + with: + push: true + tags: ghcr.io/datadog/dd-trace-rb/dd-lib-ruby-init:${{ steps.version.outputs.version }} + platforms: 'linux/amd64,linux/arm64/v8' + build-args: DDTRACE_RUBY_VERSION=${{ steps.version.outputs.version }} + context: ./lib-injection + diff --git a/lib-injection/auto_inject.rb b/lib-injection/auto_inject.rb index 01b0a0362fa..cbe17370dab 100644 --- a/lib-injection/auto_inject.rb +++ b/lib-injection/auto_inject.rb @@ -5,28 +5,34 @@ version = "" sha = "" - condition = if !version.empty? - "--version '#{version}'" - elsif !sha.empty? - "--github 'datadog/dd-trace-rb' --ref '#{sha}'" - else - puts "NO VERSION" - end + condition = + if !version.empty? + # For public release + "--version '#{version.gsub(/^v/, '')}'" + elsif !sha.empty? + # For internal testing + "--github 'datadog/dd-trace-rb' --ref '#{sha}'" + else + puts "NO VERSION" + end puts "ddtrace is not installed... Perform auto-injection... for dd-trace-rb" + # Copies for trial system "cp Gemfile Gemfile-datadog" system "cp Gemfile.lock Gemfile-datadog.lock" if system "skip_autoinject=true BUNDLE_GEMFILE=Gemfile-datadog bundle add ddtrace #{condition} --require ddtrace/auto_instrument" puts 'ddtrace added to bundle...' + # Trial success, replace the original system "cp Gemfile-datadog Gemfile" system "cp Gemfile-datadog.lock Gemfile.lock" else puts 'Something went wrong when adding ddtrace to bundle...' end + # Remove the copies system "rm Gemfile-datadog Gemfile-datadog.lock" end