From a953605427b35009f697057ab5844fccc64642ba Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Fri, 3 May 2024 16:02:37 +0200 Subject: [PATCH] github-action: run GitHub tag/release events (#169) --- .github/workflows/create-tag.yml | 15 ++++++--------- .github/workflows/release.yml | 1 - Makefile | 9 +++++++++ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-tag.yml index cc0a274..3599a50 100644 --- a/.github/workflows/create-tag.yml +++ b/.github/workflows/create-tag.yml @@ -1,5 +1,5 @@ --- -# Takes the version of elastic-apm in the requirements.txt file and creates a tag +# Creates a new GitHub release if the version in package.json changed in the main branch and # if the tag does not exist yet. name: create-tag @@ -11,7 +11,7 @@ on: - package.json permissions: - contents: write + contents: read jobs: tag: @@ -20,10 +20,7 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 # also fetch tags - - run: | - ELASTIC_APM_VERSION="v$(grep 'elastic/apm-rum"' package.json | cut -d":" -f2 | sed 's# "^##g' | sed 's#",##g')" - # 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 + + - run: make create-release + env: + GH_TOKEN: ${{ secrets.CREATE_TAG_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c2c9e26..c3e23aa 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,7 +3,6 @@ name: release on: push: branches: [ "main" ] - create: tags: [ "v*" ] permissions: diff --git a/Makefile b/Makefile index 28a035e..cfeeb88 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ PORT ?= 3000 IMAGE ?= opbeans/opbeans-frontend VERSION ?= latest LTS_ALPINE ?= 12-alpine +AGENT_VERSION=$(shell grep 'elastic/apm-rum"' package.json | cut -d"^" -f2 | sed 's|",||g') .PHONY: help .DEFAULT_GOAL := help @@ -35,3 +36,11 @@ publish: build ## Publish docker image clean: ## Clean autogenerated files/folders @rm -rf bats @rm -rf target + +create-release: ## Create github release given the APM Agent version if no tag release + @if [ -z "$(shell git tag -l v$(AGENT_VERSION))" ]; then \ + echo "creating tag v$(AGENT_VERSION)"; \ + gh release create "v$(AGENT_VERSION)" --title="$(AGENT_VERSION)" --generate-notes; \ + else \ + echo "git tag v$(AGENT_VERSION) already exists"; \ + fi