Skip to content

Create Release

Create Release #10

name: Create Release
on:
workflow_dispatch:
inputs:
package-name:
description: 'Package name (e.g., nachet or fertiscan)'
required: true
type: choice
options:
- nachet
- fertiscan
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install build dependencies
run: pip install build
- name: Configure Git for GitHub Actions
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Action"
- name: Prepare pyproject.toml for build
run: |
mv ${{ inputs.package-name }}_pyproject.toml pyproject.toml
- name: Create release zip file
run: |
zip -r release_package.zip pyproject.toml datastore ${{ inputs.package-name }}
- name: Parse version from pyproject.toml
id: parse_version
run: |
version=$(grep -Po '(?<=^version = ")[^"]*' pyproject.toml)
echo "version=$version" >> $GITHUB_ENV
- name: Tag the new version
run: |
git tag -a v${{ env.version }}-${{ inputs.package-name }}-datastore -m "Release ${{ env.version }}"
git push origin v${{ env.version }}-${{ inputs.package-name }}-datastore
- name: Generate changelog from PRs
id: generate_changelog
run: |
pr_list=$(gh pr list --repo $GITHUB_REPOSITORY --state merged --json number,title,url --jq '.[] | .number')
datastore_changelog=""
nachet_changelog=""
fertiscan_changelog=""
for pr in $pr_list; do
files=$(gh pr view "$pr" --repo $GITHUB_REPOSITORY --json files --jq '.files[].path')
# Check for changes in the datastore folder
if echo "$files" | grep -q "^datastore/"; then
pr_info=$(gh pr view "$pr" --repo $GITHUB_REPOSITORY --json title,url | jq -r '"- \(.title) (\(.url))"')
datastore_changelog="$datastore_changelog\n$pr_info"
fi
# Check for changes in the nachet folder
if [ "${{ inputs.package-name }}" = "nachet" ]; then
if echo "$files" | grep -q "^nachet/"; then
pr_info=$(gh pr view "$pr" --repo $GITHUB_REPOSITORY --json title,url | jq -r '"- \(.title) (\(.url))"')
nachet_changelog="$nachet_changelog\n$pr_info"
fi
fi
# Check for changes in the fertiscan folder
if [ "${{ inputs.package-name }}" = "fertiscan" ]; then
if echo "$files" | grep -q "^fertiscan/"; then
pr_info=$(gh pr view "$pr" --repo $GITHUB_REPOSITORY --json title,url | jq -r '"- \(.title) (\(.url))"')
fertiscan_changelog="$fertiscan_changelog\n$pr_info"
fi
fi
done
# Generate final changelog
changelog="Changelog:\n"
if [ -n "$datastore_changelog" ]; then
changelog="$changelog\nDatastore:\n$datastore_changelog"
fi
if [ -n "$nachet_changelog" ]; then
changelog="$changelog\n\nNachet:\n$nachet_changelog"
fi
if [ -n "$fertiscan_changelog" ]; then
changelog="$changelog\n\nFertiscan:\n$fertiscan_changelog"
fi
echo -e "$changelog" > RELEASE_CHANGELOG.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create GitHub Release and Replace If Exists
uses: ncipollo/release-action@v1
with:
tag: "v${{ env.version }}-${{ inputs.package-name }}-datastore"
name: "${{ inputs.package-name }}-datastore v${{ env.version }}"
bodyFile: "RELEASE_CHANGELOG.md"
allowUpdates: true
generateReleaseNotes: false
artifacts: "release_package.zip"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}