fixup! Added github actions #36
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: | | ||
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") | ||
if [ -z "$PREV_TAG" ]; then | ||
echo "No previous tag found, using initial commit." | ||
COMMITS="<ul>" | ||
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') | ||
COMMITS+="<li>$COMMIT_MSG (@$AUTHOR)</li>" | ||
done < <(git log --format="%H" HEAD) | ||
COMMITS+="</ul>" | ||
else | ||
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 "$ISSUE_URLS" | ||
echo "$ISSUE_COMMENT_URLS" | ||
echo "$PR_URLS" | ||
# Zpracování běžného commitu | ||
COMMITS+="<li>$COMMIT_MSG (@$AUTHOR)" | ||
if [[ -n "$REFERENCES" ]]; then | ||
COMMITS+=" (Referenced in: $REFERENCES)" | ||
fi | ||
if [[ -n "$PR_URLS" ]]; then | ||
COMMITS+=" (Referenced in PRs: $PR_URLS)" | ||
fi | ||
COMMITS+="</li>" | ||
done < <(git log --format="%H" $PREV_TAG..HEAD) | ||
COMMITS+="</ul>" | ||
fi | ||
# 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 }} |