From 36aa81bac8e245f8a68cc65cc248b46f34542f18 Mon Sep 17 00:00:00 2001 From: Viktor Delev Date: Mon, 11 Nov 2024 17:46:37 +0100 Subject: [PATCH 1/5] fix lin error --- .github/workflows/release-post-merge.yml | 69 ++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 .github/workflows/release-post-merge.yml diff --git a/.github/workflows/release-post-merge.yml b/.github/workflows/release-post-merge.yml new file mode 100644 index 00000000..33718a07 --- /dev/null +++ b/.github/workflows/release-post-merge.yml @@ -0,0 +1,69 @@ +name: Post-Merge Release Actions + +on: + pull_request: + types: [closed] + branches: + - 'main' + +env: + GITHUB_USER: "datavisyn-bot" + GITHUB_TOKEN: ${{ secrets.DATAVISYN_BOT_REPO_TOKEN }} + +jobs: + post_release: + if: ${{ github.event.pull_request.merged == true && startsWith(github.event.pull_request.title, 'Release') }} + runs-on: ubuntu-22.04 + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + token: ${{ secrets.CHECKOUT_TOKEN || github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }} + + - name: Generate Release Notes + id: generate-release-notes + run: | + TAG_NAME="v$(echo "${{ github.event.pull_request.title }}" | awk '{print $2}')" + response=$(curl -s -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $GITHUB_TOKEN" \ + https://api.github.com/repos/${{ github.repository }}/releases/generate-notes \ + -d "$(jq -n --arg tag_name "$TAG_NAME" \ + --arg target_commitish "main" \ + '{tag_name: $tag_name, target_commitish: $target_commitish}')") + echo "$response" | jq -r '.body' > release_notes.txt + + - name: Create GitHub Release + run: | + TAG_NAME="v$(echo "${{ github.event.pull_request.title }}" | awk '{print $2}')" + RELEASE_NOTES=$(cat release_notes.txt) + curl -X POST \ + -H "Authorization: token $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/${{ github.repository.full_name }}/releases \ + -d '{ + "tag_name": "'"$TAG_NAME"'", + "target_commitish": "main", + "name": "'"$TAG_NAME"'", + "body": "'"$RELEASE_NOTES"'", + "draft": false, + "prerelease": false + }' + + - name: Merge Main into Develop + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "<>" + git checkout develop + git pull origin main + git push origin develop + + - name: Update Package Version for Next Development Cycle + run: | + CURRENT_VERSION=$(jq -r '.version' package.json) + NEW_VERSION=$(echo "$CURRENT_VERSION" | awk -F. -v OFS=. '{$NF += 1 ; print $0"-SNAPSHOT"}') + jq --arg new_version "$NEW_VERSION" '.version = $new_version' package.json > tmp.json && mv tmp.json package.json + + git add package.json + git commit -m "Bump to $NEW_VERSION" + git push origin develop From e61935215ad0b3fc503391428dbe74ab4f54923e Mon Sep 17 00:00:00 2001 From: Viktor Delev Date: Mon, 11 Nov 2024 17:52:07 +0100 Subject: [PATCH 2/5] fix lint --- .github/workflows/release-post-merge.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release-post-merge.yml b/.github/workflows/release-post-merge.yml index 33718a07..240376cd 100644 --- a/.github/workflows/release-post-merge.yml +++ b/.github/workflows/release-post-merge.yml @@ -9,6 +9,7 @@ on: env: GITHUB_USER: "datavisyn-bot" GITHUB_TOKEN: ${{ secrets.DATAVISYN_BOT_REPO_TOKEN }} + PR_TITLE: ${{ github.event.pull_request.title }} jobs: post_release: @@ -23,7 +24,7 @@ jobs: - name: Generate Release Notes id: generate-release-notes run: | - TAG_NAME="v$(echo "${{ github.event.pull_request.title }}" | awk '{print $2}')" + TAG_NAME="v$(echo "$PR_TITLE" | awk '{print $2}')" response=$(curl -s -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer $GITHUB_TOKEN" \ From 564f9632a2ff9b5b8c8fa5eab8abce2d08e7d3a5 Mon Sep 17 00:00:00 2001 From: Viktor Delev Date: Tue, 12 Nov 2024 17:58:43 +0100 Subject: [PATCH 3/5] fix api url, changelog, tag --- .github/workflows/release-post-merge.yml | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release-post-merge.yml b/.github/workflows/release-post-merge.yml index 240376cd..4f2231eb 100644 --- a/.github/workflows/release-post-merge.yml +++ b/.github/workflows/release-post-merge.yml @@ -6,6 +6,10 @@ on: branches: - 'main' +permissions: + contents: write + pull-requests: write + env: GITHUB_USER: "datavisyn-bot" GITHUB_TOKEN: ${{ secrets.DATAVISYN_BOT_REPO_TOKEN }} @@ -20,7 +24,14 @@ jobs: uses: actions/checkout@v4 with: token: ${{ secrets.CHECKOUT_TOKEN || github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }} - + fetch-depth: 0 + + - name: Create and Push Tag + run: | + TAG_NAME="v$(echo "$PR_TITLE" | awk '{print $2}')" + git tag "$TAG_NAME" + git push origin "$TAG_NAME" + - name: Generate Release Notes id: generate-release-notes run: | @@ -36,12 +47,12 @@ jobs: - name: Create GitHub Release run: | - TAG_NAME="v$(echo "${{ github.event.pull_request.title }}" | awk '{print $2}')" + TAG_NAME="v$(echo "$PR_TITLE" | awk '{print $2}')" RELEASE_NOTES=$(cat release_notes.txt) curl -X POST \ - -H "Authorization: token $GITHUB_TOKEN" \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ -H "Accept: application/vnd.github.v3+json" \ - https://api.github.com/repos/${{ github.repository.full_name }}/releases \ + https://api.github.com/repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/releases \ -d '{ "tag_name": "'"$TAG_NAME"'", "target_commitish": "main", @@ -66,5 +77,5 @@ jobs: jq --arg new_version "$NEW_VERSION" '.version = $new_version' package.json > tmp.json && mv tmp.json package.json git add package.json - git commit -m "Bump to $NEW_VERSION" + git commit -m "chore: prepare next dev release" git push origin develop From 990a3bba0d6366b448e18535f888c9d380fdcad4 Mon Sep 17 00:00:00 2001 From: Viktor Delev Date: Tue, 12 Nov 2024 19:07:01 +0100 Subject: [PATCH 4/5] fixed api call json --- .github/workflows/release-post-merge.yml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release-post-merge.yml b/.github/workflows/release-post-merge.yml index 4f2231eb..93ea0310 100644 --- a/.github/workflows/release-post-merge.yml +++ b/.github/workflows/release-post-merge.yml @@ -53,15 +53,13 @@ jobs: -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ -H "Accept: application/vnd.github.v3+json" \ https://api.github.com/repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/releases \ - -d '{ - "tag_name": "'"$TAG_NAME"'", - "target_commitish": "main", - "name": "'"$TAG_NAME"'", - "body": "'"$RELEASE_NOTES"'", - "draft": false, - "prerelease": false - }' - + -d "$(jq -n \ + --arg tag_name "$TAG_NAME" \ + --arg target_commitish "main" \ + --arg name "$TAG_NAME" \ + --arg body "$RELEASE_NOTES" \ + '{tag_name: $tag_name, target_commitish: $target_commitish, name: $name, body: $body, draft: false, prerelease: false}')" + - name: Merge Main into Develop run: | git config user.name "$GITHUB_ACTOR" From 0ea392a9b181b303264f0afe5620b52f91ae4bc7 Mon Sep 17 00:00:00 2001 From: Viktor Delev Date: Thu, 14 Nov 2024 14:09:30 +0100 Subject: [PATCH 5/5] fix release notes, remove debug --- .github/workflows/release-post-merge.yml | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/.github/workflows/release-post-merge.yml b/.github/workflows/release-post-merge.yml index 93ea0310..9c2f73df 100644 --- a/.github/workflows/release-post-merge.yml +++ b/.github/workflows/release-post-merge.yml @@ -31,24 +31,22 @@ jobs: TAG_NAME="v$(echo "$PR_TITLE" | awk '{print $2}')" git tag "$TAG_NAME" git push origin "$TAG_NAME" - - - name: Generate Release Notes - id: generate-release-notes + + - name: Get PR body from release PR for release notes + id: get-pr-body run: | - TAG_NAME="v$(echo "$PR_TITLE" | awk '{print $2}')" - response=$(curl -s -X POST \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer $GITHUB_TOKEN" \ - https://api.github.com/repos/${{ github.repository }}/releases/generate-notes \ - -d "$(jq -n --arg tag_name "$TAG_NAME" \ - --arg target_commitish "main" \ - '{tag_name: $tag_name, target_commitish: $target_commitish}')") - echo "$response" | jq -r '.body' > release_notes.txt + echo "Fetching PR body for release notes..." + PR_RESPONSE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/pulls/${{ github.event.pull_request.number }}) + + PR_BODY=$(echo "$PR_RESPONSE" | jq -r '.body') + echo "$PR_BODY" > pr_release_notes.txt - name: Create GitHub Release run: | TAG_NAME="v$(echo "$PR_TITLE" | awk '{print $2}')" - RELEASE_NOTES=$(cat release_notes.txt) + RELEASE_NOTES=$(cat pr_release_notes.txt) curl -X POST \ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ -H "Accept: application/vnd.github.v3+json" \