Skip to content

Commit

Permalink
feat(actions): create GitHub Action
Browse files Browse the repository at this point in the history
  • Loading branch information
danth authored and relekang committed Mar 22, 2020
1 parent b6de1a6 commit 350245d
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
9 changes: 9 additions & 0 deletions 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"]
91 changes: 91 additions & 0 deletions 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: <ADD YOUR USERNAME HERE>
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: <ADD YOUR USERNAME HERE>
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: <ADD YOUR USERNAME HERE>
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
16 changes: 16 additions & 0 deletions 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 <action@github.com>"
19 changes: 19 additions & 0 deletions 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'

0 comments on commit 350245d

Please sign in to comment.