Skip to content

Commit

Permalink
Updated workflow files
Browse files Browse the repository at this point in the history
  • Loading branch information
aletail committed Apr 19, 2024
1 parent af70376 commit 83c3425
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 56 deletions.
48 changes: 16 additions & 32 deletions .github/workflows/draftrelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ name: Release Drafter
on:
push:
branches:
- release/*
- hotfix/*
- release/**
- hotfix/**

permissions:
contents: read

jobs:
update_release_draft:
permissions:
contents: write
permissions: write-all
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -27,16 +26,14 @@ jobs:
continue-on-error: true
run: |
FILTEREDBRANCHNAME=$(git branch | grep "\* release")
echo "::set-output name=filtered_branch_name::$FILTEREDBRANCHNAME"
echo "filtered_branch_name=$FILTEREDBRANCHNAME" >> $GITHUB_OUTPUT
# Get the release tag
- name: Get release Tag
id: get_release_tag
if: steps.is_release_branch.outputs.filtered_branch_name != ''
run: |
RELEASETAG=$(git branch | grep \* | sed -re "s/release\///;s/\*//;s/\s*//g")
echo "::set-output name=release_tag::$RELEASETAG"
RELEASETAG=$(git branch | grep \* | sed -re "s/(\* )?release\///;s/(\w+)\/.*/\1/g")
echo "release_tag=$RELEASETAG" >> $GITHUB_OUTPUT
# Draft Release with release branch
- name: Draft Release with release branch
id: update_release_draft_with_release_branch
Expand All @@ -56,41 +53,28 @@ jobs:
continue-on-error: true
run: |
FILTEREDBRANCHNAME=$(git branch | grep "\* hotfix")
echo "::set-output name=filtered_branch_name::$FILTEREDBRANCHNAME"
echo "filtered_branch_name=$FILTEREDBRANCHNAME" >> $GITHUB_OUTPUT
# Get the hotfix tag
- name: Get hotfix Tag
id: get_hotfix_tag
if: steps.is_hotfix_branch.outputs.filtered_branch_name != ''
run: |
RELEASETAG=$(git branch | grep \* | sed -re "s/hotfix\///;s/\*//;s/\s*//g")
echo "::set-output name=release_tag::$RELEASETAG"
# Draft Release with hotfix branch
- name: Draft Release with hotfix branch
id: update_release_draft_with_hotfix_branch
if: steps.is_hotfix_branch.outputs.filtered_branch_name != ''
uses: tiller1010/release-drafter@master
with:
tag: ${{ steps.get_hotfix_tag.outputs.release_tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


# RELEASE BRANCHING (NOT GIT-FLOW)
RELEASETAG=$(git branch | grep \* | sed -re "s/(\* )?hotfix\///;s/(\w+)\/.*/\1/g")
echo "release_tag=$RELEASETAG" >> $GITHUB_OUTPUT
# Get the last tag created on this branch
- name: Get Last Tag
id: last_tag
if: steps.is_hotfix_branch.outputs.filtered_branch_name != ''
run: |
LASTTAG=$(git describe --tags | sed -re "s/-.+//")
echo "::set-output name=last_tag_on_branch::$LASTTAG"
# Draft Release with Previous Tag
- name: Draft Release with Previous Tag
id: update_release_draft
if: steps.is_release_branch.outputs.filtered_branch_name == '' && steps.is_hotfix_branch.outputs.filtered_branch_name == ''
echo "last_tag_on_branch=$LASTTAG" >> $GITHUB_OUTPUT
# Draft Release with hotfix branch
- name: Draft Release with hotfix branch
id: update_release_draft_with_hotfix_branch
if: steps.is_hotfix_branch.outputs.filtered_branch_name != ''
uses: tiller1010/release-drafter@master
with:
tag: ${{ steps.get_hotfix_tag.outputs.release_tag }}
last_tag: ${{ steps.last_tag.outputs.last_tag_on_branch }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
140 changes: 118 additions & 22 deletions .github/workflows/publish_release_draft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,95 @@ jobs:
if: ${{ github.event.pull_request.merged }}
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@master
with:
fetch-depth: 0

- name: Get repository name
id: repo-name
uses: tiller1010/get-repo-name-action@master
with:
with-owner: 'true'

- name: Get release id
id: get_release_id
run: |
TOKEN=${{ secrets.GITHUB_TOKEN }}
RELEASEID=$(curl -H "Accept: application/vnd.github+json" -H "Authorization: token $TOKEN" https://api.github.com/repos/werkbot/silverstripe-spam-module/releases)
TOKEN="${{ secrets.GITHUB_TOKEN }}"
REPO="${{ steps.repo-name.outputs.repository-name }}"
RELEASEID=$(curl -H "Accept: application/vnd.github+json" -H "Authorization: token $TOKEN" https://api.github.com/repos/$REPO/releases)
RELEASEID=$(echo "$RELEASEID" | grep \"id\" | head -n 1 | sed -re "s/[a-z]*//g;s/[-|,|:|'\"]//g;s/\s//g")
echo "::set-output name=release_id::$RELEASEID"
echo "release_id=$RELEASEID" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Payload info
id: payload_info
uses: tiller1010/payload-info-action@master
continue-on-error: true


# START HOTFIX RELEASE RE-DRAFT
- name: Check if releasing a hotfix
id: is_hotfix_branch
continue-on-error: true
run: |
PRBRANCH="${{ steps.payload_info.outputs.branch }}"
FILTEREDBRANCHNAME=$(echo "$PRBRANCH" | grep "hotfix")
echo "filtered_pr_branch_name=$FILTEREDBRANCHNAME" >> $GITHUB_OUTPUT
- name: Get hotfix Tag from branch name
id: get_hotfix_tag
if: steps.is_hotfix_branch.outputs.filtered_pr_branch_name != ''
run: |
HOTFIXBRANCH="${{ steps.payload_info.outputs.branch }}"
RELEASETAG=$(echo "$HOTFIXBRANCH" | sed -re "s/(\* )?hotfix\///;s/(\w+)\/.*/\1/g")
echo "release_tag=$RELEASETAG" >> $GITHUB_OUTPUT
- name: Get Last Tag created on this branch
id: last_tag
if: steps.is_hotfix_branch.outputs.filtered_pr_branch_name != ''
run: |
LASTTAG=$(git describe --tags | sed -re "s/-.+//")
echo "last_tag_on_branch=$LASTTAG" >> $GITHUB_OUTPUT
# Re-Draft Release with hotfix tag
# "release-drafter" works by checking the changes of merged pull requests.
# For support or main branch hotfixes, there is only one merged hotfix PR, which is only now available,
# so we need to re-draft the release with the recently merged PR for release notes.
- name: Draft Release with hotfix tag
id: update_release_draft_with_hotfix_branch
if: steps.is_hotfix_branch.outputs.filtered_pr_branch_name != ''
uses: tiller1010/release-drafter@master
with:
tag: ${{ steps.get_hotfix_tag.outputs.release_tag }}
last_tag: ${{ steps.last_tag.outputs.last_tag_on_branch }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# END HOTFIX RELEASE RE-DRAFT


- name: Publish release
uses: eregon/publish-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ steps.get_release_id.outputs.release_id }}

- name: Payload info
id: payload_info
uses: Dovyski/payload-info-action@master
continue-on-error: true

# Generate changelog, changelog.yml is not triggered by other actions
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ steps.payload_info.outputs.pull_request.base.ref }}

# Check if this is a support branch
- name: Check For support branch
# START CHANGELOG PORTION
- name: Check if releasing for a support branch
id: is_support_branch
continue-on-error: true
run: |
FILTEREDBRANCHNAME=$(git branch | grep "\* support")
echo "::set-output name=filtered_branch_name::$FILTEREDBRANCHNAME"
echo "filtered_branch_name=$FILTEREDBRANCHNAME" >> $GITHUB_OUTPUT
- name: Generate Changelog
id: changelog
if: steps.is_support_branch.outputs.filtered_branch_name == ''
uses: loopwerk/tag-changelog@v1.0.4
uses: tiller1010/tag-changelog@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
exclude_types: other,doc,chore
Expand All @@ -63,16 +112,63 @@ jobs:
if: steps.is_support_branch.outputs.filtered_branch_name == ''
run: TAGCONTENT="${{ steps.changelog.outputs.changelog }}";CHANGELOG=$(cat CHANGELOG.md);CHANGELOG=$(echo "$CHANGELOG" | sed -e "s/# Changelog//");echo -e "# Changelog\n\n$TAGCONTENT$CHANGELOG" > CHANGELOG.md

- name: Commit Updated Changelog
- name: Create Pull Request
id: create_pr
if: steps.is_support_branch.outputs.filtered_branch_name == ''
uses: peter-evans/create-pull-request@v4
with:
title: Auto-Update CHANGELOG.md
commit-message: Updated CHANGELOG.md
labels: automerge

- name: Approve PR
if: steps.is_support_branch.outputs.filtered_branch_name == ''
uses: hmarr/auto-approve-action@v3
with:
review-message: Auto approved automated PR
pull-request-number: ${{ steps.create_pr.outputs.pull-request-number }}
github-token: ${{ secrets.SOME_USERS_PAT }}

- name: Auto merge
if: steps.is_support_branch.outputs.filtered_branch_name == ''
uses: pascalgn/automerge-action@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PULL_REQUEST: ${{ steps.create_pr.outputs.pull-request-number }}
MERGE_DELETE_BRANCH: true

- name: Post Changelog Checkout
if: steps.is_support_branch.outputs.filtered_branch_name == ''
uses: actions/checkout@master
with:
ref: main
# END CHANGELOG PORTION


# Merge support changes into develop so they can be included in the next release
- name: Merge support -> develop
if: steps.is_support_branch.outputs.filtered_branch_name != ''
uses: devmasx/merge-branch@master
with:
type: now
target_branch: develop
github_token: ${{ secrets.GITHUB_TOKEN }}
message: Merged support into develop

# Merge main changes into develop
- name: Merge main -> develop
if: steps.is_support_branch.outputs.filtered_branch_name == ''
uses: stefanzweifel/git-auto-commit-action@v4
uses: devmasx/merge-branch@master
with:
commit_message: Updated CHANGELOG.md
branch: ${{ steps.payload_info.outputs.pull_request.base.ref }}
type: now
from_branch: main
target_branch: develop
github_token: ${{ secrets.GITHUB_TOKEN }}
message: Merged main into develop

# Remove the release or hotfix branch after publishing
- name: Remove PR branch
uses: dawidd6/action-delete-branch@v3
with:
github_token: ${{github.token}}
github_token: ${{ secrets.GITHUB_TOKEN }}
branches: ${{ steps.payload_info.outputs.branch }}
5 changes: 3 additions & 2 deletions .github/workflows/pull_request_labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ jobs:
label:
runs-on: ubuntu-latest
steps:
- uses: mheap/github-action-required-labels@v2
- uses: mheap/github-action-required-labels@v3
with:
mode: exactly
count: 1
labels: "patch, minor, major"
labels: "patch, minor, major, automerge"

0 comments on commit 83c3425

Please sign in to comment.