From c96fd8d0c3b51b6b8414f1b9651b9ba19a4c39d9 Mon Sep 17 00:00:00 2001 From: santiago fraire Date: Fri, 22 Nov 2019 19:10:03 +0100 Subject: [PATCH 1/2] ci: new bump and publish github actions --- .github/workflows/bumpversion.yml | 37 ++++++++++++++++++++++++++++ .github/workflows/pythonpublish.yaml | 27 ++++++++++++++++++++ scripts/deploy | 5 ---- scripts/publish | 12 +++++++++ 4 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/bumpversion.yml create mode 100644 .github/workflows/pythonpublish.yaml delete mode 100755 scripts/deploy create mode 100755 scripts/publish diff --git a/.github/workflows/bumpversion.yml b/.github/workflows/bumpversion.yml new file mode 100644 index 0000000000..d8fcb18213 --- /dev/null +++ b/.github/workflows/bumpversion.yml @@ -0,0 +1,37 @@ +name: Bump version + +on: + push: + branches: + - master + +jobs: + build: + if: "!contains(github.event.head_commit.message, 'bump')" + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.x'] + steps: + - uses: actions/checkout@master + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python --version + python --version + python -m pip install -U commitizen + - name: Create bump + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git config --local push.followTags true + cz bump --yes + git tag + - name: Push changes + uses: Woile/github-push-action@master + with: + github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + tags: "true" diff --git a/.github/workflows/pythonpublish.yaml b/.github/workflows/pythonpublish.yaml new file mode 100644 index 0000000000..bf61909073 --- /dev/null +++ b/.github/workflows/pythonpublish.yaml @@ -0,0 +1,27 @@ +name: Upload Python Package + +on: + push: + tags: + - 'v*' + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --pre -U poetry + poetry --version + poetry install + - name: Build and publish + env: + PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }} + PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + ./scripts/publish diff --git a/scripts/deploy b/scripts/deploy deleted file mode 100755 index 52c914c71a..0000000000 --- a/scripts/deploy +++ /dev/null @@ -1,5 +0,0 @@ -# Publish to pypi -poetry publish --build - -# Publish docs -mkdocs gh-deploy diff --git a/scripts/publish b/scripts/publish new file mode 100755 index 0000000000..ec97859484 --- /dev/null +++ b/scripts/publish @@ -0,0 +1,12 @@ +# Publish to pypi +poetry publish --build -u $PYPI_USERNAME -p $PYPI_PASSWORD + +[ -z "${INPUT_GITHUB_TOKEN}" ] && { + echo 'Missing input "github_token: ${{ secrets.GITHUB_TOKEN }}".'; + exit 1; +}; + +remote_repo="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/commitizen.git" + +# Publish docs +mkdocs gh-deploy --remote-name "${remote_repo}" From 1217216950a92099196fe025f360cc7964c812a5 Mon Sep 17 00:00:00 2001 From: santiago fraire Date: Fri, 22 Nov 2019 19:32:05 +0100 Subject: [PATCH 2/2] docs: github actions tutorial --- docs/tutorials/github_actions.md | 99 ++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 docs/tutorials/github_actions.md diff --git a/docs/tutorials/github_actions.md b/docs/tutorials/github_actions.md new file mode 100644 index 0000000000..04bc976664 --- /dev/null +++ b/docs/tutorials/github_actions.md @@ -0,0 +1,99 @@ +## Create new release with Github Actions + +### Automatic bumping of version + +In order to execute `cz bump` in your CI, and push the new commit and +the new tag, back to your master branch, we have to: +1. Create a personal access token. [Follow the instructions here](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line#creating-a-token). And copy the generated key +2. Create a secret called `PERSONAL_ACCESS_TOKEN`, with the copied key, by going to your +project repository and then `Settings > Secrets > Add new secret`. +3. In your repostiroy create a new file `.github/workflows/bumpversion.yml` +with the following content. + +```yaml +name: Bump version + +on: + push: + branches: + - master # another branch could be specified here + +jobs: + build: + if: "!contains(github.event.head_commit.message, 'bump')" + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.x'] + steps: + - uses: actions/checkout@master + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python --version + python --version + python -m pip install -U commitizen + - name: Create bump + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git config --local push.followTags true + cz bump --yes + git tag + - name: Push changes + uses: Woile/github-push-action@master + with: + github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + tags: "true" +``` + +Push to master and that's it. + +### Publishing a python package + +Once the new tag is created, triggering an automatic publish command would be desired. + +In order to do so, first 2 secrets need to be added with the information +of our pypi account. + +Go to `Settings > Secrets > Add new secret` and add the secrets: `PYPI_USERNAME` and `PYPI_PASSWORD`. + +Create a file in `.github/workflows/pythonpublish.yaml` with the following content: + +```yaml +name: Upload Python Package + +on: + push: + tags: + - '*' # Will trigger for every tag, alternative: 'v*' + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --pre -U poetry + poetry --version + poetry install + - name: Build and publish + env: + PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }} + PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + ./scripts/publish +``` + +Notice that we are calling a bash script in `./scripts/publish`, you should +configure it with your tools (twine, poetry, etc). Check [commitizen example](https://github.com/Woile/commitizen/blob/master/scripts/deploy) + +Push the changes and that's it. \ No newline at end of file