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

feat: release automation #886

Merged
merged 6 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
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
72 changes: 72 additions & 0 deletions .github/workflows/create-release-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Create Release PR

on:
workflow_dispatch:
inputs:
version:
description: 'i.e. v1.14.1'
required: true

env:
git-user: kubeshop-bot
git-email: kubeshop-bot@kubeshop.io
base-branch: main
source-branch: develop

jobs:
create-pr:
runs-on: ubuntu-latest

steps:
- name: Sanitize version
run: |
VERSION=${{ github.event.inputs.version }}
echo "VERSION=$(echo "$VERSION" | sed "s/^v//")" >> "$GITHUB_ENV"

- name: Check out GitHub repo
uses: actions/checkout@v2
with:
ref: ${{ env.source-branch }}
fetch-depth: 0

- name: Configure Git
run: |
git config user.name "${{ env.git-user }}"
git config user.email "${{ env.git-email }}"

- name: Create release branch
run: git checkout -B "release/v$VERSION" && git merge origin/${{ env.base-branch }}

- name: Push release branch
run: git push -f origin "release/v$VERSION"

- name: Build log
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "CHANGELOG<<$EOF" >> "$GITHUB_ENV"
echo "$(git --no-pager log "origin/main..HEAD" --pretty='format:|[**`%h`**](https://github.com/kubeshop/testkube-dashboard/commit/%h) | %s |' 2>&1 | sed 's/ (#\([0-9]*\))[^"]/|([#\1](https:\/\/github.com\/kubeshop\/testkube-dashboard\/pull\/\1))/g' | sed 's/Merge pull request #\([0-9]*\)\(.*\)/Merge pull request #\1\2 | ([#\1](https:\/\/github.com\/kubeshop\/testkube-dashboard\/pull\/\1))/')" >> "$GITHUB_ENV"
echo "$EOF" >> "$GITHUB_ENV"

echo "FULL_CHANGELOG<<$EOF" >> "$GITHUB_ENV"
echo "$(git --no-pager log "origin/main..HEAD" --pretty='format:|[**`%h`**](https://github.com/kubeshop/testkube-dashboard/commit/%h)| %ci | %an | %s |' 2>&1 | sed 's/ (#\([0-9]*\))[^"]/|([#\1](https:\/\/github.com\/kubeshop\/testkube-dashboard\/pull\/\1))/g' | sed 's/Merge pull request #\([0-9]*\)\(.*\)/Merge pull request #\1\2 | ([#\1](https:\/\/github.com\/kubeshop\/testkube-dashboard\/pull\/\1))/')" >> "$GITHUB_ENV"
echo "$EOF" >> "$GITHUB_ENV"

- name: Create PR
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "> #### Don't forget to avoid 'Squash and Merge' - use with merge commit instead!" > message
echo "### Changelog" >> message
echo "| Commit | Description | PR |" >> message
echo "|-|-|-|" >> message
echo "$CHANGELOG" >> message
echo "" >> message
echo "<details>" >> message
echo " <summary>Details</summary>" >> message
echo "" >> message
echo " | Commit | Date | Author | Description | PR |" >> message
echo " |-|-|-|-|-|" >> message
echo " $FULL_CHANGELOG" >> message
echo "</details>" >> message

gh pr create --assignee "${{ github.triggering_actor }}" --title "Release v$VERSION" --base "${{ env.base-branch }}" --head "release/v$VERSION" --body "$(cat message)"
48 changes: 48 additions & 0 deletions .github/workflows/release-notes-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Show changelog in PR

on:
pull_request:
branches:
- main

jobs:
show-log:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Check out GitHub repo
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
fetch-depth: 0

- name: Build log
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "CHANGELOG<<$EOF" >> "$GITHUB_ENV"
echo "$(git --no-pager log "origin/${{ github.base_ref }}..HEAD" --pretty='format:|[**`%h`**](https://github.com/kubeshop/testkube-dashboard/commit/%h) | %s |' 2>&1 | sed 's/ (#\([0-9]*\))[^"]/|([#\1](https:\/\/github.com\/kubeshop\/testkube-dashboard\/pull\/\1))/g' | sed 's/Merge pull request #\([0-9]*\)\(.*\)/Merge pull request #\1\2 | ([#\1](https:\/\/github.com\/kubeshop\/testkube-dashboard\/pull\/\1))/')" >> "$GITHUB_ENV"
echo "$EOF" >> "$GITHUB_ENV"

echo "FULL_CHANGELOG<<$EOF" >> "$GITHUB_ENV"
echo "$(git --no-pager log "origin/${{ github.base_ref }}..HEAD" --pretty='format:|[**`%h`**](https://github.com/kubeshop/testkube-dashboard/commit/%h)| %ci | %an | %s |' 2>&1 | sed 's/ (#\([0-9]*\))[^"]/|([#\1](https:\/\/github.com\/kubeshop\/testkube-dashboard\/pull\/\1))/g' | sed 's/Merge pull request #\([0-9]*\)\(.*\)/Merge pull request #\1\2 | ([#\1](https:\/\/github.com\/kubeshop\/testkube-dashboard\/pull\/\1))/')" >> "$GITHUB_ENV"
echo "$EOF" >> "$GITHUB_ENV"

- name: Add comment
uses: marocchino/sticky-pull-request-comment@v2
with:
recreate: true
header: Changelog
message: |
### Changelog
| Commit | Description | PR |
|-|-|-|
${{env.CHANGELOG}}

<details>
<summary>Details</summary>

| Commit | Date | Author | Description | PR |
|-|-|-|-|-|
${{env.FULL_CHANGELOG}}
</details>
98 changes: 98 additions & 0 deletions .github/workflows/release-notes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Add changelog to the release

on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"

jobs:
show-log:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Get tag
id: tag
uses: dawidd6/action-get-tag@v1
with:
strip_v: true

- name: Check out GitHub repo
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
fetch-depth: 0

- name: Get previous tag
run: |
set -e

strip_v() { echo "$1" | sed "s/^v//"; }
find_tag() { git --no-pager tag --sort=-v:refname | grep -E "^v?$(echo "$1" | sed "s/\./\\\\./g")" | head -n 1; }

VERSION="${{ steps.tag.outputs.tag }}"

IFS=. read major minor patch <<< "$VERSION"

is_previous_tag() {
if [ -z "$1" ]; then
return 1
fi
CMP_VERSION="$(strip_v $1)"
IFS=. read pmajor pminor ppatch <<< "$CMP_VERSION"
[ "$pmajor" -lt "$major" ] && return 0
[ "$pmajor" -gt "$major" ] && return 1
[ "$pminor" -lt "$minor" ] && return 0
[ "$pminor" -gt "$minor" ] && return 1
[ "$ppatch" -lt "$patch" ] && return 0
return 1
}

PREV_TAG=""
while read prefix; do
CHECK=$(find_tag "$prefix")
if [ -z "$PREV_TAG" ] && is_previous_tag "$CHECK"; then
echo "PREV_TAG=$CHECK" >> "$GITHUB_ENV"
exit 0
fi
done <<EOF
$major.$minor.$(($patch - 1))$
$major.$minor.
$major.$(($minor - 1)).
$major.
$(($major - 1)).

EOF

>&2 echo "Could not find a previous tag for $TAG"
exit 1

- name: Build log
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "CHANGELOG<<$EOF" >> "$GITHUB_ENV"
echo "$(git --no-pager log "refs/tags/${{ env.PREV_TAG }}..HEAD" --pretty='format:|[**`%h`**](https://github.com/kubeshop/testkube-dashboard/commit/%h) | %s |' 2>&1 | sed 's/ (#\([0-9]*\))[^"]/|([#\1](https:\/\/github.com\/kubeshop\/testkube-dashboard\/pull\/\1))/g' | sed 's/Merge pull request #\([0-9]*\)\(.*\)/Merge pull request #\1\2 | ([#\1](https:\/\/github.com\/kubeshop\/testkube-dashboard\/pull\/\1))/')" >> "$GITHUB_ENV"
echo "$EOF" >> "$GITHUB_ENV"

echo "FULL_CHANGELOG<<$EOF" >> "$GITHUB_ENV"
echo "$(git --no-pager log "refs/tags/${{ env.PREV_TAG }}..HEAD" --pretty='format:|[**`%h`**](https://github.com/kubeshop/testkube-dashboard/commit/%h)| %ci | %an | %s |' 2>&1 | sed 's/ (#\([0-9]*\))[^"]/|([#\1](https:\/\/github.com\/kubeshop\/testkube-dashboard\/pull\/\1))/g' | sed 's/Merge pull request #\([0-9]*\)\(.*\)/Merge pull request #\1\2 | ([#\1](https:\/\/github.com\/kubeshop\/testkube-dashboard\/pull\/\1))/')" >> "$GITHUB_ENV"
echo "$EOF" >> "$GITHUB_ENV"

- name: Add release notes
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "### Changelog" >> message
echo "| Commit | Description | PR |" >> message
echo "|-|-|-|" >> message
echo "$CHANGELOG" >> message
echo "" >> message
echo "<details>" >> message
echo " <summary>Details</summary>" >> message
echo "" >> message
echo " | Commit | Date | Author | Description | PR |" >> message
echo " |-|-|-|-|-|" >> message
echo " $FULL_CHANGELOG" >> message
echo "</details>" >> message

gh release create -d -F message -t "Version ${{ steps.tag.outputs.tag }}" ${GITHUB_REF#refs/*/}