Skip to content

Commit

Permalink
Updates to github actions to support slack notifs and gitflow branching
Browse files Browse the repository at this point in the history
  • Loading branch information
estohlmann authored Jul 24, 2024
1 parent d7475fb commit b7039ca
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 2 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/code.draft-release-and-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Draft Release and Tag

on:
pull_request:
types: [closed]

permissions:
id-token: write
contents: write

jobs:
draft_release:
runs-on: ubuntu-latest
if: (startsWith(github.event.pull_request.head.ref, 'release/' ) || startsWith(github.event.pull_request.head.ref, 'hotfix/')) && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main'
steps:
- name: Checkout Source Tag
uses: actions/checkout@v4
with:
ref: main
- name: Get Version
id: get-version
run: |
version=$(echo ${{github.event.pull_request.head.ref}} | cut -d/ -f2)
echo "version=$version" >> $GITHUB_OUTPUT
echo "VERSION = $version"
- name: Create Release
run: |
gh release create ${{ steps.get-version.outputs.version }} --generate-notes -d -t "${{ steps.get-version.outputs.version }}" --target main
env:
GH_TOKEN: ${{ secrets.LEAD_ACCESS_TOKEN }}
send_final_slack_notification:
name: Send Final Slack Notification
needs: [draft_release]
runs-on: ubuntu-latest
if: always()
steps:
- name: Get Version
id: get-version
run: |
version=$(echo ${{github.event.pull_request.head.ref}} | cut -d/ -f2)
echo "version=$version" >> $GITHUB_OUTPUT
echo "VERSION = $version"
- name: Send Notification that Draft Release is Ready
uses: rtCamp/action-slack-notify@v2
if: (startsWith(github.event.pull_request.head.ref, 'release/' ) || startsWith(github.event.pull_request.head.ref, 'hotfix/')) && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main'
with:
status: success()
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_COLOR: ${{ contains(join(needs.*.result, ' '), 'failure') && 'failure' || 'success' }}
SLACK_TITLE: 'Build Finished'
SLACK_FOOTER: ''
MSG_MINIMAL: true
SLACK_MESSAGE_ON_FAILURE: '<!here> FAILED to publish Draft release for ${{ steps.get-version.outputs.version }}'
SLACK_MESSAGE_ON_SUCCESS: '<!here> Draft release published for <https://github.com/awslabs/LISA/releases|${{ steps.get-version.outputs.version }}>'
SLACK_MESSAGE: '<!here> Draft release finished with status ${{ job.status }} for ${{ steps.get-version.outputs.version }}'
43 changes: 43 additions & 0 deletions .github/workflows/code.hotfix.branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Make Hotfix Branch
on:
workflow_dispatch:
inputs:
source_tag:
description: 'Starting Tag'
required: true
dest_tag:
description: 'New Tag'
required: true

permissions:
id-token: write
contents: write
pull-requests: write

jobs:
MakeNewBranch:
runs-on: ubuntu-latest
steps:
- name: Checkout Source Tag
uses: actions/checkout@v4
with:
ref: refs/tags/${{ github.event.inputs.source_tag }}
- name: Create Hotfix Branch and Update Version
run: |
git config --global user.email "[email protected]"
git config --global user.name "github_actions_lisa"
SRC_TAG=${{ github.event.inputs.source_tag }}
DST_TAG=${{ github.event.inputs.dest_tag }}
git checkout -b hotfix/${{ github.event.inputs.dest_tag }}
sed -i -e "s/\"version\": \"${SRC_TAG:1}\"/\"version\": \"${DST_TAG:1}\"/g" package.json
sed -i -e "s/version = \"${SRC_TAG:1}\"/version = \"${DST_TAG:1}\"/g" lisa-sdk/pyproject.toml
sed -i -e "s/${SRC_TAG:1}/${DST_TAG:1}/g" VERSION
git commit -a -m "Updating version for hotfix ${{ github.event.inputs.dest_tag }}"
git push origin hotfix/${{ github.event.inputs.dest_tag }}
env:
GITHUB_TOKEN: ${{ secrets.LEAD_ACCESS_TOKEN }}
- name: Draft Pull Request
run: |
gh pr create -d --title "Hotfix ${{github.event.inputs.dest_tag}} into Main" --body "Hotfix ${{github.event.inputs.dest_tag}} PR into Main" --base main --head hotfix/${{ github.event.inputs.dest_tag }}
env:
GH_TOKEN: ${{ github.token }}
46 changes: 46 additions & 0 deletions .github/workflows/code.merge.main-to-develop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Merge Main into Develop

on:
release:
types: [released]

permissions:
id-token: write
contents: write

jobs:
conduct_merge:
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v4
with:
ref: main
- name: merge main into develop
run: |
git config --global user.email "[email protected]"
git config --global user.name "github_actions_lisa"
git fetch --unshallow
git checkout develop
git pull
git merge --no-ff origin/main -m "Auto-merge main back to dev post release"
git push --force origin develop
env:
GH_TOKEN: ${{ secrets.LEAD_ACCESS_TOKEN }}
send_final_slack_notification:
name: Send Final Slack Notification
needs: [conduct_merge]
runs-on: ubuntu-latest
if: always()
steps:
- name: Send Notification that Develop is up to date
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.INTERNAL_DEV_SLACK_WEBHOOK_URL }}
SLACK_COLOR: ${{ contains(join(needs.*.result, ' '), 'failure') && 'failure' || 'success' }}
SLACK_TITLE: 'Main merged into Develop'
SLACK_FOOTER: ''
MSG_MINIMAL: true
SLACK_MESSAGE_ON_FAILURE: '<!here> New Release has been <${{ github.event.release.html_url }}|published>! FAILED to merge main into Develop.'
SLACK_MESSAGE_ON_SUCCESS: '<!here> New Release has been <${{ github.event.release.html_url }}|published>! Main was SUCCESSFULLY merged into Develop.'
SLACK_MESSAGE: '<!here> New Release has been <${{ github.event.release.html_url }}|published>! Merging main into develop finished with status ${{ job.status }}.'
39 changes: 39 additions & 0 deletions .github/workflows/code.release.branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Make Release Branch
on:
workflow_dispatch:
inputs:
release_tag:
description: 'New Release Name'
required: true

permissions:
id-token: write
contents: write
pull-requests: write

jobs:
MakeNewReleaseBranch:
runs-on: ubuntu-latest
steps:
- name: Checkout Develop Branch
uses: actions/checkout@v4
with:
ref: develop
- name: Create Release Branch and Update Version
run: |
git config --global user.email "[email protected]"
git config --global user.name "github_actions_lisa"
RELEASE_TAG=${{ github.event.inputs.release_tag }}
git checkout -b release/${{ github.event.inputs.release_tag }}
echo "$( jq --arg version ${RELEASE_TAG:1} '.version = $version' package.json )" > package.json
sed -E -i '' -e "s/version = \"[0-9\.].+\"/version = \"${RELEASE_TAG:1}\"/g" lisa-sdk/pyproject.toml
echo ${RELEASE_TAG:1} > VERSION
git commit -a -m "Updating version for release ${{ github.event.inputs.release_tag }}"
git push origin release/${{ github.event.inputs.release_tag }}
env:
GITHUB_TOKEN: ${{ secrets.LEAD_ACCESS_TOKEN }}
- name: Draft Pull Request
run: |
gh pr create -d --title "Release ${{github.event.inputs.release_tag}} into Main" --body "Release ${{github.event.inputs.release_tag}} PR into Main" --base main --head release/${{ github.event.inputs.release_tag }}
env:
GH_TOKEN: ${{ github.token }}
37 changes: 35 additions & 2 deletions .github/workflows/test-and-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@ name: Build and Test

on:
push:
branches: ['main']
branches: ['main', 'develop', 'release/**', 'hotfix/**']
pull_request:
branches: ['main']
branches: ['main', 'develop', 'release/**', 'hotfix/**']

permissions:
contents: read

jobs:
send_starting_slack_notification:
name: Send Starting Slack Notification
runs-on: ubuntu-latest
steps:
- name: Send PR Created Notification
if: github.event_name == 'pull_request' && github.event.action == 'opened'
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_TITLE: 'PR Created: ${{ github.event.pull_request.title }} by ${{ github.event.pull_request.user.login }}'
SLACK_FOOTER: ''
MSG_MINIMAL: true
SLACK_MESSAGE: 'PR Created ${{ github.event.pull_request.html_url }}'
cdk-build:
name: CDK Tests
needs: [send_starting_slack_notification]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -27,6 +41,7 @@ jobs:
npm run test
pre-commit:
name: Run All Pre-Commit
needs: [send_starting_slack_notification]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -47,3 +62,21 @@ jobs:
run: |
npm install
- uses: pre-commit/[email protected]
send_final_slack_notification:
name: Send Final Slack Notification
needs: [cdk-build, pre-commit]
runs-on: ubuntu-latest
if: always()
steps:
- name: Send GitHub Action trigger data to Slack workflow
uses: rtCamp/action-slack-notify@v2
if: github.event_name != 'pull_request'
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_COLOR: ${{ contains(join(needs.*.result, ' '), 'failure') && 'failure' || 'success' }}
SLACK_TITLE: 'Build Finished'
SLACK_FOOTER: ''
MSG_MINIMAL: 'actions url,commit'
SLACK_MESSAGE_ON_FAILURE: '<!here> Build FAILED on branch ${{ github.head_ref || github.ref_name }} for <${{ github.event.pull_request.html_url || github.event.head_commit.url }}|commit>'
SLACK_MESSAGE_ON_SUCCESS: 'Build SUCCESS on branch ${{ github.head_ref || github.ref_name }} for <${{ github.event.pull_request.html_url || github.event.head_commit.url }}|commit>.'
SLACK_MESSAGE: 'Build Finished with status ${{ job.status }} on branch ${{ github.head_ref || github.ref_name }} for <${{ github.event.pull_request.html_url || github.event.head_commit.url }}|commit>'

0 comments on commit b7039ca

Please sign in to comment.