Skip to content

Commit

Permalink
Try to create a github release pushing a git tag
Browse files Browse the repository at this point in the history
  • Loading branch information
joserc87 committed Jul 10, 2024
1 parent 3888e19 commit 31450cc
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/changelogtext.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
set -e

PACKAGE_VERSION=${1:-$(sed -r 's/__version__ = "(.*)"/\1/' ravenpackapi/version.py)}

# Make sure the version is in the changelog
grep -n "^## \[v$PACKAGE_VERSION] \(.*\)" CHANGELOG.md >/dev/null \
|| (echo "Error. Version $PACKAGE_VERSION not in changelog" \
&& exit 1)
LINE_BEFORE=$( \
grep -n "^## \[v$PACKAGE_VERSION] \(.*\)" CHANGELOG.md \
| cut -d: -f1 \
| head -n 1 \
)

# * cut from after the header of the current package version
# * select all the other headers, showing the linue numbers
# * get the line number of the first header
LINE_AFTER=$( \
tail -n +$LINE_BEFORE CHANGELOG.md \
| tail -n +2 \
| grep -n "^## \[v.*\] \(.*\)" \
| sed -r 's/(.*):## \[v(.*)\] \(.*\)/\1:\2/' \
| cut -d: -f1 \
| head -1
)

LINE_BEFORE=$((LINE_BEFORE + 1))
LINE_AFTER=$((LINE_AFTER + LINE_BEFORE))
LINE_AFTER=$((LINE_AFTER - 2))
# Extract range and remove empty lines from the beginning and end of the file
sed -n "$LINE_BEFORE,$LINE_AFTER p" CHANGELOG.md \
| awk 'NF {p=1} p' | tac | awk 'NF {p=1} p' | tac
41 changes: 41 additions & 0 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Create a github release for a git tag
on:
push:
tags:
- 'v*.*.*'
- 'v*.*'
jobs:
# Check that the tag matches the lastest version in the code
check-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check version
run: |
# Get the latest version from the code
latest_version=$(sed -r 's/__version__ = "(.*)"/\1/' ravenpackapi/version.py)
# Get the tag from the git tag
tag=$(echo $GITHUB_REF | sed -r 's/refs\/tags\/v(.*)/\1/')
# Check that the tag matches the latest version
if [ "$latest_version" != "$tag" ]; then
echo "The tag $tag does not match the latest version $latest_version"
exit 1
fi
# Create a release
github-release:
name: >-
📦✍ Sign the package with Sigstore
and upload them to GitHub Release
runs-on: ubuntu-latest
needs: check-version
steps:
- uses: actions/checkout@v4
- name: Dump the changelog
run: .github/changelogtext.sh > '${{ github.ref_name }}.md'
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
latest_version=$(sed -r 's/__version__ = "(.*)"/\1/' ravenpackapi/version.py)
gh release create '${{ github.ref_name }}' -F '${{ github.ref_name }}.md' --title "Version $latest_version" --repo '${{ github.repository }}'

0 comments on commit 31450cc

Please sign in to comment.