Skip to content

Commit

Permalink
feat: cicd - create rls draft on tags
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-perkins committed Oct 22, 2024
1 parent 7d4577f commit 45d1f96
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/create-release-draft.yml
Original file line number Diff line number Diff line change
@@ -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 }}
45 changes: 45 additions & 0 deletions scripts/create-release-draft.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

# Usage: ./create_release.sh <tag_name>

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

0 comments on commit 45d1f96

Please sign in to comment.