-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updating ci-cd.yml to also create release automatically
- Loading branch information
1 parent
d745161
commit 3e3a937
Showing
1 changed file
with
35 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,12 @@ on: | |
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
release: | ||
types: [published] | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
description: 'Version to release (leave empty to use version from _version.py)' | ||
required: false | ||
type: string | ||
|
||
jobs: | ||
build: | ||
|
@@ -35,7 +39,7 @@ jobs: | |
publish: | ||
needs: [build] | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'release' && github.event.action == 'published' | ||
if: github.event_name == 'workflow_dispatch' | ||
permissions: | ||
id-token: write | ||
contents: write | ||
|
@@ -52,19 +56,43 @@ jobs: | |
python -m pip install --upgrade pip | ||
pip install . | ||
pip install build twine | ||
- name: Extract version from _version.py | ||
- name: Extract version and update if necessary | ||
id: extract_version | ||
run: | | ||
VERSION=$(python -c "from etekcity_esf551_ble._version import __version__; print(__version__)") | ||
echo "VERSION=$VERSION" >> $GITHUB_ENV | ||
if [ -n "${{ github.event.inputs.version }}" ]; then | ||
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV | ||
sed -i "s/__version__ = .*/__version__ = \"${{ github.event.inputs.version }}\"/" src/etekcity_esf551_ble/_version.py | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git add src/etekcity_esf551_ble/_version.py | ||
git commit -m "Bump version to ${{ github.event.inputs.version }}" | ||
git push | ||
else | ||
VERSION=$(python -c "from etekcity_esf551_ble._version import __version__; print(__version__)") | ||
echo "VERSION=$VERSION" >> $GITHUB_ENV | ||
fi | ||
- name: Build package | ||
run: python -m build | ||
- name: Create GitHub Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: v${{ env.VERSION }} | ||
release_name: Release v${{ env.VERSION }} | ||
draft: false | ||
prerelease: false | ||
- name: Upload to PyPI | ||
env: | ||
TWINE_USERNAME: __token__ | ||
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | ||
run: | | ||
twine upload dist/* | ||
- name: Wait for PyPI | ||
run: | | ||
echo "Waiting for package to be available on PyPI..." | ||
sleep 60 | ||
- name: Verify installation from PyPI | ||
run: | | ||
python -m venv test-env | ||
|
@@ -88,7 +116,7 @@ jobs: | |
await github.rest.repos.uploadReleaseAsset({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
release_id: context.payload.release.id, | ||
release_id: ${{ steps.create_release.outputs.id }}, | ||
name: file, | ||
data: await fs.readFile(filePath) | ||
}); | ||
|