Skip to content

Merge pull request #1635 from saleweaver/dependabot/pip/master/boto3-… #156

Merge pull request #1635 from saleweaver/dependabot/pip/master/boto3-…

Merge pull request #1635 from saleweaver/dependabot/pip/master/boto3-… #156

name: CI
on:
push:
branches:
- master
jobs:
versioning:
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
steps:
- name: Checkout code
if: github.actor != 'dependabot[bot]'
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
if: github.actor != 'dependabot[bot]'
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Increment version
if: github.actor != 'dependabot[bot]'
uses: saleweaver/version_increment_action@v1
with:
file_path: "sp_api/__version__.py"
version_key: "__version__"
- name: Install Dependencies
if: env.new_version != '' && github.actor != 'dependabot[bot]'
run: |
python -m pip install --upgrade pip
pip install openai
- name: Get Latest Bump Version Commits
if: env.new_version != '' && github.actor != 'dependabot[bot]'
id: get_commits
run: |
COMMITS=$(git log --grep='^Bump version' --pretty=format:"%H" -n 2)
echo $COMMITS
echo "commits<<EOF" >> $GITHUB_OUTPUT
echo "$COMMITS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Generate Diff
if: env.new_version != '' && github.actor != 'dependabot[bot]'
id: generate_diff
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
COMMITS="${{ steps.get_commits.outputs.commits }}"
COMMITS_ARRAY=($COMMITS)
if [ ${#COMMITS_ARRAY[@]} -lt 2 ]; then
echo "No previous Bump version commit found. Skipping changelog."
echo "diff=" >> $GITHUB_OUTPUT
exit 0
fi
OLD_COMMIT=${COMMITS_ARRAY[1]}
NEW_COMMIT=${COMMITS_ARRAY[0]}
git diff $OLD_COMMIT $NEW_COMMIT > changelog_diff.patch
python generate_changelog.py changelog_diff.patch
- name: Update CHANGELOG.md
if: env.new_version != '' && github.actor != 'dependabot[bot]'
run: |
# Write the new version header and generated entry to a temp file
echo "## v${{ env.new_version }} - $(date +'%Y-%m-%d')" > temp_changelog.md
cat changelog_entry.md >> temp_changelog.md
echo "" >> temp_changelog.md
# Append the old CHANGELOG.md content after the new entry
if [ -f CHANGELOG.md ]; then
cat CHANGELOG.md >> temp_changelog.md
fi
# Move temp back to CHANGELOG.md
mv temp_changelog.md CHANGELOG.md
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add CHANGELOG.md
git commit -m "chore: update CHANGELOG.md for v${{ env.new_version }}"
git push
- name: Read Changelog Entry
if: env.new_version != '' && github.actor != 'dependabot[bot]'
id: read_changelog
run: |
echo "body<<EOF" >> $GITHUB_OUTPUT
cat changelog_entry.md >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create a new GitHub release
if: env.new_version != '' && github.actor != 'dependabot[bot]'
uses: actions/create-release@v1
with:
tag_name: "v${{ env.new_version }}"
release_name: "v${{ env.new_version }}"
body: ${{ steps.read_changelog.outputs.body }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Trigger release workflow
if: env.new_version != '' && github.actor != 'dependabot[bot]'
run: |
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/dispatches \
-d '{"event_type": "release_created", "client_payload": { "version": "${{ env.new_version }}" }}'