From 350245dbfb07ed6a1db017b1d9d1072b368b1497 Mon Sep 17 00:00:00 2001 From: Daniel Thwaites Date: Thu, 19 Mar 2020 18:28:58 +0000 Subject: [PATCH] feat(actions): create GitHub Action --- Dockerfile | 9 ++++++ action.rst | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ action.sh | 16 ++++++++++ action.yml | 19 ++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 Dockerfile create mode 100644 action.rst create mode 100755 action.sh create mode 100644 action.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..289a3a61f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +# This Dockerfile is only for GitHub Actions + +FROM python:3.7 + +COPY . /python-semantic-release +RUN python -m pip install /python-semantic-release + +COPY action.sh /action.sh +ENTRYPOINT ["/action.sh"] diff --git a/action.rst b/action.rst new file mode 100644 index 000000000..0930150b5 --- /dev/null +++ b/action.rst @@ -0,0 +1,91 @@ +GitHub Action for Python Semantic Release +========================================= + +Inputs +------ + ++-------------------+-------------------------------------------------+ +| Input | Description | ++===================+=================================================+ +| ``github_token`` | **Required.** The GitHub token used to push | +| | release notes and new commits/tags created by | +| | the tool. Usually | +| | ``${{ secrets.GITHUB_TOKEN }}``. | ++-------------------+-------------------------------------------------+ +| ``pypi_username`` | **Required unless upload_to_pypi is false in | +| | setup.cfg.** Username with project access to | +| | push to PyPi. | ++-------------------+-------------------------------------------------+ +| ``pypi_password`` | **Required unless upload_to_pypi is false in | +| | setup.cfg.** Password to the account specified | +| | in ``pypi_username``. | ++-------------------+-------------------------------------------------+ +| ``directory`` | A sub-directory to ``cd`` into before running. | +| | Defaults to the root of the repository. | ++-------------------+-------------------------------------------------+ + +Further options are **required** to be configured in either +``setup.cfg`` or ``pyproject.toml`` as documented `here`_. + +Example Workflow +---------------- + +.. code:: yaml + + name: Semantic Release + + on: + push: + branches: + - master + + jobs: + release: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + + - name: Python Semantic Release + uses: relekang/python-semantic-release@v4 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + pypi_username: + pypi_password: ${{ secrets.PYPI_PASSWORD }} + +``PYPI_PASSWORD`` should be set as a secret on your repository's +settings page. It is safe to include your username directly in the +configuration, although you could also set it as a secret if you wish. +The ``GITHUB_TOKEN`` secret is automatically configured by Actions. + +Multiple Projects +~~~~~~~~~~~~~~~~~ + +If you have multiple projects stored within a single repository (or your +project is not at the root of the repository), you can pass the +``directory`` input. The step can be called multiple times to release +multiple projects. + +.. code:: yaml + + - name: Release Project 1 + uses: relekang/python-semantic-release@v4 + with: + directory: ./project1 + github_token: ${{ secrets.GITHUB_TOKEN }} + pypi_username: + pypi_password: ${{ secrets.PYPI_PASSWORD }} + + - name: Release Project 2 + uses: relekang/python-semantic-release@v4 + with: + directory: ./project2 + github_token: ${{ secrets.GITHUB_TOKEN }} + pypi_username: + pypi_password: ${{ secrets.PYPI_PASSWORD }} + +Note that the release notes posted to GitHub will not currently +distinguish which project they are from (see `this issue`_). + +.. _here: https://python-semantic-release.readthedocs.io/en/latest/configuration.html +.. _this issue: https://github.com/relekang/python-semantic-release/issues/168 diff --git a/action.sh b/action.sh new file mode 100755 index 000000000..11ee873bc --- /dev/null +++ b/action.sh @@ -0,0 +1,16 @@ +#!/bin/sh -l + +# Copy inputs into correctly-named environment variables +export GH_TOKEN="${INPUT_GITHUB_TOKEN}" +export PYPI_USERNAME="${INPUT_PYPI_USERNAME}" +export PYPI_PASSWORD="${INPUT_PYPI_PASSWORD}" + +# Change to configured directory +cd "${INPUT_DIRECTORY}" + +# Set Git details +git config --global user.name "github-actions" +git config --global user.email "action@github.com" + +# Run Semantic Release +DEBUG="*" semantic-release publish -D commit_author="github-actions " diff --git a/action.yml b/action.yml new file mode 100644 index 000000000..ccb3b85d6 --- /dev/null +++ b/action.yml @@ -0,0 +1,19 @@ +name: 'Python Semantic Release' + +description: 'Automatic semantic versioning for python projects' + +inputs: + directory: + description: 'Sub-directory to cd into before running semantic-release' + default: '.' + github_token: + description: 'GitHub token used to push release notes and new commits/tags' + required: true + pypi_username: + description: 'Username with project access to push to PyPi' + pypi_password: + description: 'Password to the account specified in pypi_username' + +runs: + using: 'docker' + image: 'Dockerfile'