Skip to content

Commit

Permalink
ci(github): update release workflow to work around semantic-release l…
Browse files Browse the repository at this point in the history
…imitations
  • Loading branch information
darvid committed Dec 12, 2020
1 parent 88b63e3 commit 6975583
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 13 deletions.
107 changes: 101 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,19 @@ jobs:
PYTHON_VERSION: ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Build and test
run: |
PYTHONDIR=/opt/python/${PYTHON_VERSION}
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
${PYTHONDIR}/bin/pip install -UI poetry setuptools
${PYTHONDIR}/bin/poetry build -vvv
${PYTHONDIR}/bin/poetry install --no-root
${PYTHONDIR}/bin/poetry run semantic-release version -v DEBUG \
-D commit_author="github-actions <[email protected]>"
${PYTHONDIR}/bin/poetry install
${PYTHONDIR}/bin/poetry build -vvv
${PYTHONDIR}/bin/poetry run pytest -vvv tests/
- name: Archive dist
uses: actions/upload-artifact@v2
Expand All @@ -47,13 +54,46 @@ jobs:
path: |
dist/*.whl
dist/*.tar.gz
release:
prepare_release:
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-python@v2
with:
python-version: "3.9"
architecture: "x64"
- name: Generate release changelog
run: |
pip install "python-semantic-release==7.6.0"
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
semantic-release version -v DEBUG -D commit_author="github-actions <[email protected]>"
semantic-release changelog -v DEBUG > RELEASE_CHANGELOG
git push --follow-tags
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Archive release changelog
uses: actions/upload-artifact@v2
with:
name: changelog
path: |
RELEASE_CHANGELOG
- name: Remove release changelog
run: rm -f RELEASE_CHANGELOG
release:
runs-on: ubuntu-latest
needs: prepare_release
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Pull from origin
run: git pull origin master
- name: Download dist
uses: actions/download-artifact@v2
with:
Expand All @@ -62,8 +102,63 @@ jobs:
- name: Display dist
run: ls -R
working-directory: dist
- name: Python Semantic Release
uses: relekang/[email protected]
- name: Capture package version
id: package_version
run: |
tar xvzf dist/*.tar.gz --no-anchored --strip=1 PKG-INFO
VERSION=$(grep "^Version" PKG-INFO | tr -d ' ' | cut -d: -f2)
rm -f PKG-INFO
echo "Package version: $VERSION"
echo "::set-output name=release_version::v$VERSION"
- name: Capture current commit tag
id: git_tag
run: |
TAG_VERSION=$(git tag --points-at HEAD)
echo "Current tag: $TAG_VERSION"
echo "::set-output name=current_tag::$TAG_VERSION"
- name: Download release changelog
uses: actions/download-artifact@v2
if: ${{ steps.git_tag.outputs.current_tag == steps.package_version.outputs.release_version }}
with:
name: changelog
- name: Create release
id: create_release
if: ${{ steps.git_tag.outputs.current_tag == steps.package_version.outputs.release_version }}
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.package_version.outputs.release_version }}
release_name: Release ${{ steps.package_version.outputs.release_version }}
body_path: RELEASE_CHANGELOG
draft: false
prerelease: false
- name: Delete RELEASE_CHANGELOG
run: rm -f RELEASE_CHANGELOG
- name: Upload release assets
uses: actions/github-script@v3
if: ${{ steps.git_tag.outputs.current_tag == steps.package_version.outputs.release_version }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const path = require('path');
const fs = require('fs');
const release_id = '${{ steps.create_release.outputs.id }}';
for (let file of await fs.readdirSync('./dist')) {
if (path.extname(file) === '.gz' || path.extname(file) === '.whl') {
console.log('uploadReleaseAsset', file);
await github.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release_id,
name: file,
data: await fs.readFileSync(`./dist/${file}`)
});
}
}
- name: Upload to PyPI
if: ${{ steps.git_tag.outputs.current_tag == steps.package_version.outputs.release_version }}
uses: pypa/gh-action-pypi-publish@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
pypi_token: ${{ secrets.PYPI_TOKEN }}
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

<!--next-version-placeholder-->

## [0.1.5] - 2020-02-21

### Fixed
Expand Down
Loading

0 comments on commit 6975583

Please sign in to comment.