diff --git a/.github/workflows/release-post-merge.yml b/.github/workflows/release-post-merge.yml new file mode 100644 index 00000000..9c2f73df --- /dev/null +++ b/.github/workflows/release-post-merge.yml @@ -0,0 +1,77 @@ +name: Post-Merge Release Actions + +on: + pull_request: + types: [closed] + branches: + - 'main' + +permissions: + contents: write + pull-requests: write + +env: + GITHUB_USER: "datavisyn-bot" + GITHUB_TOKEN: ${{ secrets.DATAVISYN_BOT_REPO_TOKEN }} + PR_TITLE: ${{ github.event.pull_request.title }} + +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 }} + 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: Get PR body from release PR for release notes + id: get-pr-body + run: | + 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 pr_release_notes.txt) + curl -X POST \ + -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 "$(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" + 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 "chore: prepare next dev release" + git push origin develop