- Go to organization Settings -> Actions -> General find Workflow permissions and turn on Read and write permissions
Last active
December 14, 2024 15:55
-
-
Save JanGalek/e3c1c0fc143431eff4f7a9c65ae1479a to your computer and use it in GitHub Desktop.
Github actions create release note
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Commit Lint | |
on: | |
pull_request: | |
types: [opened, synchronize, edited] | |
push: | |
branches: | |
- master | |
- main | |
- develop | |
- feature/** | |
- release/** | |
jobs: | |
lint-commits: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Lint commit messages | |
run: | | |
COMMITS=$(git log --pretty=format:"%s" HEAD^..HEAD 2>/dev/null || git log --pretty=format:"%s" HEAD) | |
REGEX="^\[(Add|Fix|Update|Remove|Refactor|Docs|Test|Improve)\] .{10,}$" | |
echo "$COMMITS" | while read -r COMMIT; do | |
if [[ ! $COMMIT =~ $REGEX ]]; then | |
echo "Invalid commit message: $COMMIT" | |
echo "Commit messages must match: '[TYPE] Description' (e.g., '[Add] New feature')." | |
exit 1 | |
fi | |
done | |
- name: Commit messages are valid | |
run: echo "All commit messages are valid!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Create Release | |
on: | |
push: | |
tags: | |
- 'v*' | |
workflow_dispatch: | |
inputs: | |
tag_name: | |
description: 'Tag name for the release' | |
required: true | |
default: 'v1.0.0' | |
release_type: | |
description: 'Release type (stable, beta, rc)' | |
required: true | |
default: 'stable' | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Install GitHub CLI | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y gh | |
- name: Authenticate GitHub CLI | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: gh auth setup-git | |
- name: Determine release type | |
id: release_type | |
run: | | |
TAG_NAME=${{ github.ref_name }} | |
if [[ "$TAG_NAME" == *beta* ]]; then | |
echo "release_type=Pre-release (Beta)" >> $GITHUB_ENV | |
echo "prerelease=true" >> $GITHUB_ENV | |
elif [[ "$TAG_NAME" == *rc* ]]; then | |
echo "release_type=Pre-release (Release Candidate)" >> $GITHUB_ENV | |
echo "prerelease=true" >> $GITHUB_ENV | |
else | |
echo "release_type=Stable" >> $GITHUB_ENV | |
echo "prerelease=false" >> $GITHUB_ENV | |
fi | |
- name: Get commits since last tag | |
id: commits | |
run: | | |
# Získání aktuálního tagu | |
CURRENT_TAG=$(git describe --tags --abbrev=0 HEAD) | |
# Funkce pro získání předchozího stabilního tagu | |
get_previous_stable_tag() { | |
PREV_TAG="" | |
# Procházej všechny tagy v obráceném pořadí (od nejnovějšího) | |
for tag in $(git tag --sort=-creatordate); do | |
# Pokud je tag stabilní (např. v1.0.0, v1.2.3, atd.), ale není stejný jako aktuální | |
if [[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] && [[ "$tag" != "$CURRENT_TAG" ]]; then | |
PREV_TAG=$tag | |
break | |
fi | |
done | |
echo $PREV_TAG | |
} | |
# Pokud je aktuální tag beta nebo rc, najdi poslední stabilní verzi | |
if [[ "$CURRENT_TAG" =~ -beta || "$CURRENT_TAG" =~ -rc ]]; then | |
# Najdi poslední stabilní verzi (ignoruj beta/rc tagy) | |
PREV_TAG=$(git tag --sort=-creatordate | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1) | |
else | |
# Pokud je stabilní verze, použij předchozí stabilní tag | |
PREV_TAG=$(git tag --sort=-creatordate | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | grep -B 1 "$CURRENT_TAG" | head -n 1) | |
fi | |
if [[ "$CURRENT_TAG" == "$PREV_TAG" ]]; then | |
echo "Current tag is the same as the previous tag, using the previous stable tag." | |
PREV_TAG=$(get_previous_stable_tag) | |
fi | |
if [ -z "$PREV_TAG" ]; then | |
echo "No previous tag found, using initial commit." | |
PREV_TAG=$(git rev-list --max-parents=0 HEAD) | |
fi | |
echo "PREV TAG: $PREV_TAG" | |
echo "CURRENT TAG: $CURRENT_TAG" | |
COMMITS="<ul>" | |
declare -A FIXUPS | |
# Iterace přes všechny commity od posledního tagu | |
while read -r commit_hash; do | |
COMMIT_MSG=$(git log -n 1 --pretty=format:"%s" "$commit_hash") | |
AUTHOR=$(gh api "/repos/${{ github.repository }}/commits/$commit_hash" --jq '.author.login') | |
# Kontrola, zda jde o fixup commit | |
if [[ "$COMMIT_MSG" == fixup!* ]]; then | |
ORIGINAL_HASH=$(git log -n 1 --format="%H" "$commit_hash"^) | |
FIXUPS["$ORIGINAL_HASH"]+="$commit_hash " | |
continue | |
fi | |
# Hledání uzavřených issue nebo PR pro tento commit | |
COMMIT_URL="https://github.com/${{ github.repository }}/commit/$commit_hash" | |
echo "Checking commit: $COMMIT_URL" | |
ISSUE_URLS=$(gh api "/repos/${{ github.repository }}/issues?state=closed" --jq "[.[] | select(.body != null and (.body | test(\"(Resolve|Close).*${commit_hash}\")))][].html_url" || echo "") | |
ISSUE_COMMENT_URLS=$(gh api "/repos/${{ github.repository }}/issues/comments" --jq "[.[] | select(.body != null and (.body | test(\"(Resolve|Close).*${commit_hash}\")))][].html_url" || echo "") | |
PR_URLS=$(gh api "/repos/${{ github.repository }}/pulls?state=all" --jq "[.[] | select(.body != null and (.body | contains(\"${commit_hash}\")))][].html_url" || echo "") | |
REFERENCES="$ISSUE_URLS $ISSUE_COMMENT_URLS" | |
echo "VANILA" | |
echo "$ISSUE_URLS" | |
echo "$ISSUE_COMMENT_URLS" | |
echo "$PR_URLS" | |
ISSUE_URLS=$(echo "$ISSUE_URLS" | sed 's/#issuecomment-[0-9]*//g') | |
ISSUE_COMMENT_URLS=$(echo "$ISSUE_COMMENT_URLS" | sed 's/#issuecomment-[0-9]*//g') | |
echo "CLEARED" | |
echo "$ISSUE_URLS" | |
echo "$ISSUE_COMMENT_URLS" | |
echo "$PR_URLS" | |
# Zpracování běžného commitu | |
COMMITS+="<li>$COMMIT_MSG (@$AUTHOR)" | |
# Přidání všech odkazů na Issues | |
if [[ -n "$ISSUE_URLS" ]]; then | |
COMMITS+=", (Referenced in Issues: " | |
# Seznam odkazů oddělený mezerou | |
COMMITS+=$(echo "$ISSUE_URLS" | tr '\n' ' ' | sed -E "s|https://github.com/${{ github.repository }}/issues/([0-9]+)|<a href=\"https://github.com/${{ github.repository }}/issues/\1\">#\1</a>|g" | sed 's/ / , /g') | |
COMMITS=$(echo "$COMMITS" | sed 's/, $//') | |
COMMITS+=" )" | |
fi | |
# Přidání všech odkazů na komentáře | |
if [[ -n "$ISSUE_COMMENT_URLS" ]]; then | |
COMMITS+=", (Referenced in Comments: " | |
# Seznam odkazů oddělený mezerou | |
COMMITS+=$(echo "$ISSUE_COMMENT_URLS" | tr '\n' ' '| sed -E "s|https://github.com/${{ github.repository }}/issues/([0-9]+)|<a href=\"https://github.com/${{ github.repository }}/issues/\1\">#\1</a>|g" | sed 's/ / , /g') | |
COMMITS=$(echo "$COMMITS" | sed 's/, $//') | |
COMMITS+=" )" | |
fi | |
# Přidání všech odkazů na PRs | |
if [[ -n "$PR_URLS" ]]; then | |
COMMITS+=", (Referenced in PRs: " | |
COMMITS+=$(echo "$PR_URLS" | tr '\n' ' '| sed -E "s|https://github.com/${{ github.repository }}/pulls/([0-9]+)|<a href=\"https://github.com/${{ github.repository }}/pulls/\1\">#\1</a>|g" | sed 's/ / , /g') | |
COMMITS=$(echo "$COMMITS" | sed 's/, $//') | |
COMMITS+=" )" | |
fi | |
COMMITS+="</li>" | |
done < <(git log --format="%H" $PREV_TAG..HEAD) | |
COMMITS+="</ul>" | |
# Odstranění nechtěných znaků | |
COMMITS=$(echo "$COMMITS" | sed 's/[[:cntrl:]]//g') | |
echo "commits=$COMMITS" >> $GITHUB_ENV | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create release | |
uses: ncipollo/release-action@v1 | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag: ${{ github.ref_name }} | |
body: | | |
${{ env.commits }} | |
draft: false | |
prerelease: ${{ env.prerelease }} | |
name: ${{ github.ref_name }} - ${{ env.release_type }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment