Release(manually) #3
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
on: | |
workflow_dispatch: | |
name: Release(manually) | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python 3.11 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.11.5" | |
check-latest: true | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip setuptools wheel | |
if [ -f build_requirements.txt ]; then pip install -r build_requirements.txt; fi | |
- name: Setting version | |
run: | | |
VAR1=$(python version.py) | |
IFS=' ' read -r VAR2 VAR3 <<< "$VAR1" | |
echo "VERSION=$VAR2" >> "$GITHUB_OUTPUT" | |
echo "LOG_PATH=$VAR3" >> "$GITHUB_OUTPUT" | |
id: version_parse | |
- name: Build package | |
run : python -m build | |
- name: Upload /dist | |
uses: actions/upload-artifact@v3 | |
with: | |
name: python-package-distributions | |
path: dist/*.tar.gz # only source distribution | |
- name: Get the file name and path in /dist | |
run: | | |
VAR1=$(find ./dist -type f -name "*.tar.gz") | |
VAR2=$(basename $VAR1) | |
echo $VAR2 | |
echo "TAR_FILE=$VAR2" >> "$GITHUB_OUTPUT" | |
echo "TAR_PATH=$VAR1" >> "$GITHUB_OUTPUT" | |
id: filename | |
- name: Commit and push changes | |
run: | | |
status=$(git status -s) | |
if [ -z "$status" ] || [ "$status" = $'\n' ]; then | |
echo "nothing to commit, working tree clean" | |
else | |
git config --global user.name "Auto commit (Github release workflow)" | |
git config --global user.email "elen98725@gmail.com" | |
git add . | |
git commit -m "commit by auto commit" | |
fi | |
git tag $VERSION | |
git push origin $VERSION main | |
env: | |
VERSION: ${{ steps.version_parse.outputs.VERSION }} | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.version_parse.outputs.VERSION }} | |
release_name: Release ${{ steps.version_parse.outputs.VERSION }} | |
body_path: ${{ steps.version_parse.outputs.LOG_PATH }} | |
draft: false | |
prerelease: false | |
- name: Upload Release Asset | |
id: upload-release-asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps | |
asset_path: ${{ steps.filename.outputs.TAR_PATH }} | |
asset_name: ${{ steps.filename.outputs.TAR_FILE }} | |
asset_content_type: application/gzip | |
# publish-to-testpypi: | |
# name: Publish Python distribution 📦 to TestPyPI | |
# needs: | |
# - build | |
# runs-on: ubuntu-latest | |
# environment: | |
# name: testpypi | |
# url: https://test.pypi.org/p/<package-name> # Replace <package-name> with your TestPyPI project name | |
# permissions: | |
# id-token: write # IMPORTANT: mandatory for trusted publishing | |
# steps: | |
# - name: Download all the dists | |
# uses: actions/download-artifact@v3 | |
# with: | |
# name: python-package-distributions | |
# path: dist/ | |
# - name: Publish distribution 📦 to TestPyPI | |
# uses: pypa/gh-action-pypi-publish@release/v1 | |
# with: | |
# repository-url: https://test.pypi.org/legacy/ | |
# publish-to-pypi: | |
# name: >- | |
# Publish Python distribution 📦 to PyPI | |
# needs: | |
# - build | |
# runs-on: ubuntu-latest | |
# environment: | |
# name: pypi | |
# url: https://pypi.org/p/<package-name> # Replace <package-name> with your PyPI project name | |
# permissions: | |
# id-token: write # IMPORTANT: mandatory for trusted publishing | |
# steps: | |
# - name: Download all the dists | |
# uses: actions/download-artifact@v3 | |
# with: | |
# name: python-package-distributions | |
# path: dist/ | |
# - name: Publish distribution 📦 to PyPI | |
# uses: pypa/gh-action-pypi-publish@release/v1 |