# Copyright © 2012-2023 jrnl contributors # License: https://www.gnu.org/licenses/gpl-3.0.html name: Release on: workflow_dispatch: inputs: version: description: 'Version (e.g. v2.5, v2.5.1-beta, v2.6-beta2)' type: string required: true include_repo_version: description: 'Update version in repo?' type: boolean required: true default: true include_pypi: description: 'Publish to PyPI?' type: boolean required: true default: true jobs: validate: name: "Validate version string" runs-on: ubuntu-latest steps: - name: Validate version run: | JRNL_VERSION="${{ github.event.inputs.version }}" echo "::debug::version: $JRNL_VERSION" if [[ ! $JRNL_VERSION =~ ^v[0-9]+(\.[0-9]+){1,2}(-(alpha|beta)([0-9]+)?)?$ ]]; then echo echo "::error::Bad version" echo echo "Version string should match pattern above." echo "Here are some examples of valid version numbers:" echo echo " v2.5" echo " v2.5-alpha" echo " v2.5-beta" echo " v2.5.1" echo " v2.5.1-alpha" echo " v2.5.1-beta" exit 1 fi release_pypi: needs: validate name: "Release to PyPI" runs-on: ubuntu-latest outputs: pypi_version: ${{ steps.pypi-version-getter.outputs.pypi_version }} env: HOME_REPO: ${{ secrets.HOME_REPO }} steps: - name: Get version run: | JRNL_VERSION="${{ github.event.inputs.version }}" echo "::debug::version: $JRNL_VERSION" echo "JRNL_VERSION=$JRNL_VERSION" >> "$GITHUB_ENV" - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.13' - name: Checkout repo uses: actions/checkout@v4 with: token: ${{ secrets.JRNL_BOT_TOKEN }} - name: Config git user run: | git config --global user.name "${{ secrets.JRNL_BOT_NAME }}" git config --global user.email "${{ secrets.JRNL_BOT_EMAIL }}" - name: Install dependencies run: pip install poetry - name: Update version in files if: ${{ github.event.inputs.include_repo_version == 'true' }} run: | poetry version "$JRNL_VERSION" echo "__version__ = \"$JRNL_VERSION\"" > jrnl/__version__.py - name: Commit updated files if: ${{ github.event.inputs.include_repo_version == 'true' && github.repository == env.HOME_REPO }} run: | git add pyproject.toml jrnl/__version__.py git commit -m "Increment version to ${JRNL_VERSION}" git tag -a -m "$JRNL_VERSION" "$JRNL_VERSION" git push git push --tags - name: Build run: poetry build - name: Deploy to PyPI if: ${{ github.event.inputs.include_pypi == 'true' && github.repository == env.HOME_REPO }} env: POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }} run: poetry publish - name: Get PyPI version id: pypi-version-getter run: | pypi_version="$(find dist/jrnl-*.tar.gz | sed -r 's!dist/jrnl-(.*)\.tar\.gz!\1!')" echo "pypi_version=$pypi_version" >> "$GITHUB_OUTPUT"