From 53a74b1358e1dfcce9383737737ce24dbfe02a4b Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 23 Feb 2023 14:06:47 +0100 Subject: [PATCH 1/5] Bump version with updatecli --- .ci/bump-gem.sh | 19 ++++++ .ci/bump-opbeans-ruby.yml | 80 +++++++++++++++++++++++++ .ci/bump-version.sh | 42 ------------- .github/workflows/bump-opbeans-ruby.yml | 24 ++++++++ .github/workflows/create-tag.yml | 29 +++++++++ 5 files changed, 152 insertions(+), 42 deletions(-) create mode 100755 .ci/bump-gem.sh create mode 100644 .ci/bump-opbeans-ruby.yml delete mode 100755 .ci/bump-version.sh create mode 100644 .github/workflows/bump-opbeans-ruby.yml create mode 100644 .github/workflows/create-tag.yml diff --git a/.ci/bump-gem.sh b/.ci/bump-gem.sh new file mode 100755 index 0000000..59724fa --- /dev/null +++ b/.ci/bump-gem.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -euxo pipefail + +# Update elastic-apm in Gemfile +sed -ibck "s#\(gem 'elastic-apm', \)\('.*'\)\(.*\)#\1'${1}'\3#g" Gemfile + +RUBY_VERSION=$(grep '^ruby' Gemfile | awk '{ print $2 }' | tr -d \') +## Use docker to bump the version to ensure the environment is easy to reproduce. +docker run --rm -t \ + --user $UID \ + -e LOCAL_USER_ID=$UID \ + -e HOME=/tmp \ + -e AGENT_VERSION="${NEW_AGENT_VERSION}" \ + -w /app \ + -v "$(pwd):/app" \ + "ruby:${RUBY_VERSION}" /bin/sh -c "set -x + # This version is fixed in the Gemfile.lock + gem install bundler -v 2.2.22 + bundle update elastic-apm" diff --git a/.ci/bump-opbeans-ruby.yml b/.ci/bump-opbeans-ruby.yml new file mode 100644 index 0000000..639f203 --- /dev/null +++ b/.ci/bump-opbeans-ruby.yml @@ -0,0 +1,80 @@ +--- +## Workflow to periodically check if there is an available newer APM agent version, e.g. +## "1.2.3". If so, then update to it. +name: Bump elastic-apm to latest version + +title: Bump elastic-apm to latest version + +scms: + elastic-apm-agent-ruby: + kind: github + spec: + user: '{{ requiredEnv "GIT_USER" }}' + email: '{{ requiredEnv "GIT_EMAIL" }}' + owner: elastic + repository: apm-agent-ruby + token: '{{ requiredEnv "GITHUB_TOKEN" }}' + username: '{{ requiredEnv "GIT_USER" }}' + branch: main + githubConfig: + kind: github + spec: + user: '{{ requiredEnv "GIT_USER" }}' + email: '{{ requiredEnv "GIT_EMAIL" }}' + owner: elastic + repository: opbeans-ruby + token: '{{ requiredEnv "GITHUB_TOKEN" }}' + username: '{{ requiredEnv "GIT_USER" }}' + branch: main + +actions: + opbeans-ruby: + kind: github/pullrequest + scmid: githubConfig + spec: + automerge: false + labels: + - dependencies + +sources: + elastic-apm-agent-ruby: + scmid: elastic-apm-agent-ruby + kind: gittag + spec: + versionfilter: + kind: semver + transformers: + - trimprefix: "v" + +targets: + dockerfile-label-schema: + name: Set org.label-schema.version in Dockerfile + sourceid: elastic-apm-agent-ruby + scmid: githubConfig + kind: file + spec: + file: Dockerfile + matchpattern: >- + org\.label-schema\.version="(\d+.\d+.\d+)" + replacepattern: >- + org.label-schema.version="{{ source `elastic-apm-agent-ruby` }}" + dockerfile-opencontainers: + name: Set org.label-schema.version in Dockerfile + sourceid: elastic-apm-agent-ruby + scmid: githubConfig + kind: file + spec: + file: Dockerfile + matchpattern: >- + org\.opencontainers.image.version="(\d+.\d+.\d+)" + replacepattern: >- + org.opencontainers.image.version="{{ source `elastic-apm-agent-ruby` }}" + gem: + name: Bump elastic-apm + sourceid: elastic-apm-agent-ruby + scmid: githubConfig + kind: shell + spec: + command: ./.ci/bump-gem.sh + environments: + - name: PATH diff --git a/.ci/bump-version.sh b/.ci/bump-version.sh deleted file mode 100755 index 78c0c9d..0000000 --- a/.ci/bump-version.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env bash -set -euxo pipefail - -AGENT_VERSION="${1?Missing the APM ruby agent version}" - -## Normalise the agent version that it's coming from the tag name. -NEW_AGENT_VERSION=$(echo ${AGENT_VERSION} | sed 's#^v##g') - -## Gather ruby version -RUBY_VERSION=$(grep '^ruby' Gemfile | sed -E "s/.*[\"'](.+)[\"']/\1/") - -# Update elastic-apm in Gemfile -sed -ibck "s#\(gem 'elastic-apm', \)\('.*'\)\(.*\)#\1'${NEW_AGENT_VERSION}'\3#g" Gemfile - -## Bump agent version in the Dockerfile -sed -ibck "s#\(org.label-schema.version=\)\(\".*\"\)\(.*\)#\1\"${NEW_AGENT_VERSION}\"\3#g" Dockerfile -sed -ibck "s#\(org.opencontainers.image.version=\)\(\".*\"\)\(.*\)#\1\"${NEW_AGENT_VERSION}\"\3#g" Dockerfile - -## Use docker to bump the version to ensure the environment is easy to reproduce. -docker run --rm -t \ - --user $UID \ - -e LOCAL_USER_ID=$UID \ - -e HOME=/tmp \ - -e AGENT_VERSION="${NEW_AGENT_VERSION}" \ - -w /app \ - -v "$(pwd):/app" \ - ruby:${RUBY_VERSION} /bin/sh -c "set -x - # This version is fixed in the Gemfile.lock - gem install bundler -v 2.2.22 - bundle update elastic-apm" - -# Validate whether the agent version matches -git diff --name-only -S"elastic-apm (${NEW_AGENT_VERSION})" | grep Gemfile.lock && found=1 || found=0 -if [ ${found} -eq 0 ] ; then - echo 'ERROR: Agent version was not updated. See the below diff detail output:' - git diff --unified=0 Gemfile.lock - exit 1 -fi - -# Commit changes -git add Gemfile.lock Gemfile Dockerfile -git commit -m "fix(package): bump elastic-apm to version ${NEW_AGENT_VERSION}" diff --git a/.github/workflows/bump-opbeans-ruby.yml b/.github/workflows/bump-opbeans-ruby.yml new file mode 100644 index 0000000..b23c74f --- /dev/null +++ b/.github/workflows/bump-opbeans-ruby.yml @@ -0,0 +1,24 @@ +--- +## Workflow to periodically check if there is an available newer APM agent version, e.g. +## "1.2.3". If so, then update to it and tag this repo with that version, e.g. +## "v1.2.3". +name: bump-opbeans-ruby + +on: + schedule: + - cron: '0 20 * * 6' + +permissions: + contents: read + +jobs: + bump: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: elastic/apm-pipeline-library/.github/actions/updatecli@current + with: + vaultUrl: ${{ secrets.VAULT_ADDR }} + vaultRoleId: ${{ secrets.VAULT_ROLE_ID }} + vaultSecretId: ${{ secrets.VAULT_SECRET_ID }} + pipeline: ./.ci/bump-opbeans-node.yml diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-tag.yml new file mode 100644 index 0000000..5b02f2d --- /dev/null +++ b/.github/workflows/create-tag.yml @@ -0,0 +1,29 @@ +--- +# Takes the version of elastic-apm in the Gemfile and creates a tag +# if the tag does not exist yet. +name: create-tag + +on: + push: + branches: + - main + paths: + - Gemfile + +permissions: + contents: write + +jobs: + tag: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # also fetch tags + - run: | + ELASTIC_APM_VERSION="v$(cat Gemfile | grep elastic-apm | awk 'BEGIN { FS=", " } { print $2 }' | tr -d \')" + # if the tag does not exist + if [[ ! $(git tag -l "${ELASTIC_APM_VERSION}") ]]; then + git tag ${ELASTIC_APM_VERSION} + git push origin "refs/tags/${ELASTIC_APM_VERSION}" + fi From 9e4bc2154d6673661c87965ea6c78852ac47f2dd Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 23 Feb 2023 14:27:36 +0100 Subject: [PATCH 2/5] Update .github/workflows/bump-opbeans-ruby.yml Co-authored-by: Victor Martinez --- .github/workflows/bump-opbeans-ruby.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bump-opbeans-ruby.yml b/.github/workflows/bump-opbeans-ruby.yml index b23c74f..659aa4f 100644 --- a/.github/workflows/bump-opbeans-ruby.yml +++ b/.github/workflows/bump-opbeans-ruby.yml @@ -21,4 +21,4 @@ jobs: vaultUrl: ${{ secrets.VAULT_ADDR }} vaultRoleId: ${{ secrets.VAULT_ROLE_ID }} vaultSecretId: ${{ secrets.VAULT_SECRET_ID }} - pipeline: ./.ci/bump-opbeans-node.yml + pipeline: ./.ci/bump-opbeans-ruby.yml From bec01713d36fa013fd1174dff276b4de5d336e8b Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 23 Feb 2023 14:29:12 +0100 Subject: [PATCH 3/5] fix --- .ci/bump-opbeans-ruby.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.ci/bump-opbeans-ruby.yml b/.ci/bump-opbeans-ruby.yml index 639f203..7dd92f8 100644 --- a/.ci/bump-opbeans-ruby.yml +++ b/.ci/bump-opbeans-ruby.yml @@ -59,14 +59,14 @@ targets: replacepattern: >- org.label-schema.version="{{ source `elastic-apm-agent-ruby` }}" dockerfile-opencontainers: - name: Set org.label-schema.version in Dockerfile + name: Set org.opencontainers.image.version in Dockerfile sourceid: elastic-apm-agent-ruby scmid: githubConfig kind: file spec: file: Dockerfile matchpattern: >- - org\.opencontainers.image.version="(\d+.\d+.\d+)" + org\.opencontainers\.image\.version="(\d+.\d+.\d+)" replacepattern: >- org.opencontainers.image.version="{{ source `elastic-apm-agent-ruby` }}" gem: From cdfa3183077144cc685873e6ab3ba7fe1f8cd3c4 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 23 Feb 2023 16:03:44 +0100 Subject: [PATCH 4/5] Refactor --- .ci/bump-gem.sh | 19 ------------------- .ci/bump-opbeans-ruby.yml | 15 ++++++++++++++- .github/workflows/bump-opbeans-ruby.yml | 4 ++++ 3 files changed, 18 insertions(+), 20 deletions(-) delete mode 100755 .ci/bump-gem.sh diff --git a/.ci/bump-gem.sh b/.ci/bump-gem.sh deleted file mode 100755 index 59724fa..0000000 --- a/.ci/bump-gem.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash -set -euxo pipefail - -# Update elastic-apm in Gemfile -sed -ibck "s#\(gem 'elastic-apm', \)\('.*'\)\(.*\)#\1'${1}'\3#g" Gemfile - -RUBY_VERSION=$(grep '^ruby' Gemfile | awk '{ print $2 }' | tr -d \') -## Use docker to bump the version to ensure the environment is easy to reproduce. -docker run --rm -t \ - --user $UID \ - -e LOCAL_USER_ID=$UID \ - -e HOME=/tmp \ - -e AGENT_VERSION="${NEW_AGENT_VERSION}" \ - -w /app \ - -v "$(pwd):/app" \ - "ruby:${RUBY_VERSION}" /bin/sh -c "set -x - # This version is fixed in the Gemfile.lock - gem install bundler -v 2.2.22 - bundle update elastic-apm" diff --git a/.ci/bump-opbeans-ruby.yml b/.ci/bump-opbeans-ruby.yml index 7dd92f8..8a76cec 100644 --- a/.ci/bump-opbeans-ruby.yml +++ b/.ci/bump-opbeans-ruby.yml @@ -69,12 +69,25 @@ targets: org\.opencontainers\.image\.version="(\d+.\d+.\d+)" replacepattern: >- org.opencontainers.image.version="{{ source `elastic-apm-agent-ruby` }}" + gemfile: + name: Install new elastic-apm pip dependency version + sourceid: elastic-apm-agent-ruby + scmid: githubConfig + kind: file + spec: + file: Gemfile + matchpattern: >- + gem 'elastic-apm', '\d+\.\d+\.\d+' + replacepattern: >- + gem 'elastic-apm', '{{ source `elastic-apm-agent-ruby` }}' gem: + dependson: + - gemfile name: Bump elastic-apm sourceid: elastic-apm-agent-ruby scmid: githubConfig kind: shell spec: - command: ./.ci/bump-gem.sh + command: bundle update elastic-apm environments: - name: PATH diff --git a/.github/workflows/bump-opbeans-ruby.yml b/.github/workflows/bump-opbeans-ruby.yml index 659aa4f..1f14b02 100644 --- a/.github/workflows/bump-opbeans-ruby.yml +++ b/.github/workflows/bump-opbeans-ruby.yml @@ -16,6 +16,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: '2.7.3' + bundler-cache: true # runs 'bundle install' and caches installed gems automatically - uses: elastic/apm-pipeline-library/.github/actions/updatecli@current with: vaultUrl: ${{ secrets.VAULT_ADDR }} From af3f812222f4add1dda53fba11c37032e704dc34 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 23 Feb 2023 16:05:41 +0100 Subject: [PATCH 5/5] remove bundle cache --- .github/workflows/bump-opbeans-ruby.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/bump-opbeans-ruby.yml b/.github/workflows/bump-opbeans-ruby.yml index 1f14b02..c62ec1d 100644 --- a/.github/workflows/bump-opbeans-ruby.yml +++ b/.github/workflows/bump-opbeans-ruby.yml @@ -19,7 +19,6 @@ jobs: - uses: ruby/setup-ruby@v1 with: ruby-version: '2.7.3' - bundler-cache: true # runs 'bundle install' and caches installed gems automatically - uses: elastic/apm-pipeline-library/.github/actions/updatecli@current with: vaultUrl: ${{ secrets.VAULT_ADDR }}