Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make releaser work between PR and Push events #817

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions .github/workflows/releaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ name: Release Tagging

on:
pull_request:
types: [opened, reopened, synchronize, closed]
types: [opened]

push:
branches:
- main

permissions:
contents: write # Allows pushing changes and creating tags
Expand All @@ -11,7 +15,7 @@ permissions:

jobs:
tag-discussion:
if: github.event.action == 'opened'
if: github.event_name == 'pull_request' && github.event.action == 'opened'
runs-on: ubuntu-latest
steps:
- name: Checkout Code
Expand All @@ -22,16 +26,15 @@ jobs:
run: |
git fetch --tags
LATEST_TAG=$(git tag --sort=-v:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
echo "latest tag: $LATEST_TAG"
if [ -z "$LATEST_TAG" ]; then
LATEST_TAG="0.0.0"
fi
MAJOR=$(echo $LATEST_TAG | cut -d. -f1)
MINOR=$(echo $LATEST_TAG | cut -d. -f2)
PATCH=$(echo $LATEST_TAG | cut -d. -f3)


NEW_PATCH_VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
NEW_MINOR_VERSION="$MAJOR.$((MINOR + 1)).0"
NEW_MAJOR_VERSION="$((MAJOR + 1)).0.0"

echo "patch_version=$NEW_PATCH_VERSION" >> $GITHUB_OUTPUT
echo "minor_version=$NEW_MINOR_VERSION" >> $GITHUB_OUTPUT
echo "major_version=$NEW_MAJOR_VERSION" >> $GITHUB_OUTPUT
Expand All @@ -50,18 +53,36 @@ jobs:
- 🚀 for **Major** ${{ steps.calculate_versions.outputs.major_version }} update

determine-tag:
if: github.event.action == 'closed' && github.event.pull_request.merged == true && github.ref == 'refs/heads/main'
needs: tag-discussion
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Determine the next version based on comments
id: determine_version
- name: Find the Merged Pull Request
id: find_pr
run: |
BASE_BRANCH="main"
RECENT_PR=$(gh pr list --state closed --base $BASE_BRANCH --json number,title,closedAt --jq '.[] | select(.closedAt >= "'$(date -u -d '1 minute ago' +%Y-%m-%dT%H:%M:%SZ)'") | {number, title}')
echo "RECENT_PR=$RECENT_PR" >> $GITHUB_ENV
echo "PR_NUMBER=$(echo $RECENT_PR | jq -r '.number')" >> $GITHUB_ENV

- name: Fetch latest stable tag (excluding prerelease tags)
id: get_latest_tag
run: |
git fetch --tags
LATEST_TAG=$(git tag --sort=-v:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
if [ -z "$LATEST_TAG" ]; then
LATEST_TAG="0.0.0"
fi
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT

- name: Determine the next version based on comments
id: determine_version
env:
PR_NUMBER: ${{ env.PR_NUMBER }}
run: |
LATEST_TAG=${{ steps.get_latest_tag.outputs.latest_tag }}
MAJOR=$(echo $LATEST_TAG | cut -d. -f1)
MINOR=$(echo $LATEST_TAG | cut -d. -f2)
PATCH=$(echo $LATEST_TAG | cut -d. -f3)
Expand All @@ -74,7 +95,7 @@ jobs:
REACTION=$(gh api graphql -f query='
query {
repository(owner:"${{ github.repository_owner }}", name:"${{ github.event.repository.name }}") {
pullRequest(number: ${{ github.event.pull_request.number }}) {
pullRequest(number: '${PR_NUMBER}') {
comments(last: 100) {
nodes {
body
Expand All @@ -99,7 +120,6 @@ jobs:
.content'
)


# Determine the new tag version based on the allowed reactions
if [[ "$REACTION" == *"ROCKET"* ]]; then
NEW_TAG="$((MAJOR + 1)).0.0"
Expand Down
Loading