From 45d1f96b08face8f1cfb5034f07c89bf667702de Mon Sep 17 00:00:00 2001 From: Jake Perkins Date: Mon, 21 Oct 2024 22:14:14 -0500 Subject: [PATCH] feat: cicd - create rls draft on tags --- .github/workflows/create-release-draft.yml | 29 ++++++++++++++ scripts/create-release-draft.sh | 45 ++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 .github/workflows/create-release-draft.yml create mode 100755 scripts/create-release-draft.sh diff --git a/.github/workflows/create-release-draft.yml b/.github/workflows/create-release-draft.yml new file mode 100644 index 00000000000..9069da82b4e --- /dev/null +++ b/.github/workflows/create-release-draft.yml @@ -0,0 +1,29 @@ +name: create-release-draft + +on: + push: + tags: + - 'v*' + +permissions: + contents: write + pull-requests: read + +jobs: + draft_release: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + ref: ${{ github.ref }} # Explicitly specifies the tag ref + + + - name: Setup GitHub CLI + run: | + sudo apt update + sudo apt install gh + echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token + + - name: Create Draft Release + run: ./scripts/create-release-draft.sh ${{ github.ref_name }} ${{ github.workspace }} \ No newline at end of file diff --git a/scripts/create-release-draft.sh b/scripts/create-release-draft.sh new file mode 100755 index 00000000000..4d8f51c189b --- /dev/null +++ b/scripts/create-release-draft.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# Usage: ./create_release.sh + +TAG_NAME=$1 +REPO_PATH=$2 # Ensure the script is executed in the repository's root directory + +# Navigate to the repository path (if not already there) +cd $REPO_PATH || exit 1 + +# Get the commit ID for the tag +RELEASE_COMMIT_ID=$(git rev-list -n 1 "$TAG_NAME") + +echo "Creating a draft release for tag $TAG_NAME with commit ID $RELEASE_COMMIT_ID" + +CHANGELOG_TAG_NAME=${1#v} # Remove 'v' prefix if present + +#Parse the release notes from the CHANGELOG.md file + +RELEASE_NOTES=$(awk -v version="$CHANGELOG_TAG_NAME" ' + # Start printing if the line exactly matches the version heading format + $0 ~ "^## " version " - " { + printit = 1; + } + # Continue printing if printit was set + printit { + if (/^## [0-9]+\.[0-9]+\.[0-9]+/ && $0 !~ version) { + printit = 0; # Stop printing immediately before printing this line + } else { + print $0; + } + } +' CHANGELOG.md) + +# Prepend the header to the release notes +HEADER=$'Thanks for trying out MetaMask Mobile! We really appreciate your feedback 🤗.\n\n## Table of Contents\n- [What’s new](https://github.com/MetaMask/metamask-mobile/blob/main/CHANGELOG.md)\n- [Feedback](https://github.com/MetaMask/metamask-mobile/issues/new?assignees=&labels=&projects=&template=general-issue.yml)\n\n' +FULL_RELEASE_NOTES="$HEADER$RELEASE_NOTES" + +# Create a draft release using GitHub CLI +gh release create \ + "$TAG_NAME" \ + --title "$TAG_NAME" \ + --notes "$FULL_RELEASE_NOTES" \ + --target "$RELEASE_COMMIT_ID" \ + --draft