Skip to content

Create Release

Create Release #38

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
with:
fetch-depth: 0
- name: Configure Git for GitHub Actions
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Action"
- name: Move appropriate pyproject.toml for build
run: |
mv ${{ inputs.package-name }}_pyproject.toml pyproject.toml
- name: Parse version from pyproject.toml
id: parse_version
run: |
version=$(grep -Po '(?<=^version = ")[^"]*' pyproject.toml)
echo "version=$version" >> $GITHUB_ENV
- name: Switch to the release branch
run: |
git checkout -b ${{ inputs.package-name }}-${{ env.version }}
git push -u origin ${{ inputs.package-name }}-${{ env.version }}
- name: Remove unnecessary files from release branch
run: |
find . -path "./.git" -prune -o -type f ! -name "pyproject.toml" ! -name "requirements.txt" ! -path "./datastore/*" ! -path "./${{ inputs.package-name }}/*" -exec rm -f {} +
find . -type d \( -path "./.git" -o -path ./"datastore" -o -path "./${{ inputs.package-name }}" \) -prune -o -type d ! -path "." -exec rm -rf {} +
- uses: EndBug/add-and-commit@v9
with:
message: "Release v${{ env.version }}-${{ inputs.package-name }}-datastore"
add: "."
author_name: "GitHub Action"
author_email: [email protected]
- name: Tag the clean version on the release branch
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
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
makeLatest: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}