Skip to content

Commit

Permalink
ci: revise release action for poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnakumar committed Oct 30, 2023
1 parent 8cf609d commit dd491c5
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ poetry.lock export-ignore
pytest.ini export-ignore
TODO.md export-ignore
webpack.config.js export-ignore
webpack.serve.config.js export-ignore
webpack.serve.config.js export-ignore
CHANGELOG.md export-ignore
2 changes: 1 addition & 1 deletion .github/workflows/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def extract_changelog_content(changelog: Any, version):
version_extract_pattern = r"(^[#]{2}.*\[" + re.escape(version) + r"\][\s\S]*?(?=^[#]{2}\s))"
version_extract = re.search(version_extract_pattern, changelog_text, re.MULTILINE)
if header and version_extract:
return f"{header.group()}\n{version_extract.group()}"
return f"{header.group().strip()}\n\n{version_extract.group().strip()}".strip()
else:
return None

Expand Down
65 changes: 41 additions & 24 deletions .github/workflows/python-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,48 @@ jobs:
pull-requests: write

steps:
- uses: actions/checkout@v4.1.1
- name: Checkout Repo
id: checkout
uses: actions/checkout@v4.1.1
with:
token: ${{ secrets.GIT_TOKEN }}
fetch-depth: 2
ref: ${{ github.event.repository.default_branch }}
fetch-depth: 0

- name: Check if there is a parent commit
id: check-parent-commit
run: |
echo "sha=$(git rev-parse --verify --quiet HEAD^)" | tee -a "$GITHUB_OUTPUT"
- uses: actions/setup-node@v4.0.0
- name: Setup node
uses: actions/setup-node@v4.0.0
with:
node-version: '${{ env.NODE_VERSION }}'
registry-url: https://registry.npmjs.org/

- name: Set up Python
uses: actions/setup-python@v4.7.1
with:
python-version: '${{ env.PYTHON_VERSION }}'

- name: Install poetry
uses: Gr1N/setup-poetry@v8
with:
poetry-version: '${{ env.POETRY_VERSION }}'

- name: Cache poetry
id: cached-poetry-dependencies
uses: actions/cache@v3.3.2
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ env.POETRY_VERSION }}-${{ hashFiles('poetry.lock') }}-python-${{ env.PYTHON_VERSION }}

- id: check-poetry-version-is-valid
- name: Check package version is valid
id: check-poetry-version-is-valid
run: poetry --version

- name: Install dependencies
id: install-dependencies
run: poetry install

- name: Detect and tag new version
Expand All @@ -68,47 +78,54 @@ jobs:
VERSION="$(bash -o pipefail -c "poetry version | awk '{ print \$2 }'")"
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "RELEASE_VERSION=v${VERSION}" >> $GITHUB_OUTPUT
echo "RELEASE_INFO='Release for Package Version v${VERSION}'" >> $GITHUB_OUTPUT
echo "RELEASE_INFO=v${VERSION}" >> $GITHUB_OUTPUT
- name: Create release branch and build python package
- name: Build python package
if: steps.get-version.outputs.RELEASE_VERSION != ''
id: create-release-branch-and-build
id: build-for-release-branch
run: |
git config --global user.name "peakmaster"
export rbranch="release/${{ steps.get-version.outputs.RELEASE_VERSION }}"
git branch $rbranch
pip install pyclean
sed -i '/dash_extensions\/*/d' .gitignore
poetry run npm install || echo "Ignore npm install error"
poetry run npm run build
git add .
git commit -am "chore: create release for ${{ steps.get-version.outputs.RELEASE_VERSION }}"
git push origin $rbranch --force
poetry run npm run build_no_r
poetry build --ansi
tar xvf ./dist/dash_extensions-${{ steps.get-version.outputs.VERSION }}.tar.gz
rsync --recursive ./dash_extensions-${{ steps.get-version.outputs.VERSION }}/* .
rm -rf ./dash_extensions-${{ steps.get-version.outputs.VERSION }}
export rbranch="release/${{ steps.get-version.outputs.RELEASE_VERSION }}"
echo "RELEASE_BRANCH=$rbranch" >> $GITHUB_OUTPUT
pyclean .
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Commit changes to Release Branch
if: steps.build-for-release-branch.outputs.RELEASE_BRANCH != ''
id: commit-and-create-branch
uses: EndBug/add-and-commit@v9.1.3
with:
add: '[".gitignore --force", "dash_extensions/* --force", "PKG-INFO", "."]'
new_branch: "release/${{ steps.get-version.outputs.RELEASE_VERSION }}"
message: "ci: create release for ${{ steps.get-version.outputs.RELEASE_VERSION }}"
push: "origin release/${{ steps.get-version.outputs.RELEASE_VERSION }} --force"

- name: Read CHANGELOG.md and use it as body of new release
if: steps.create-release-branch-and-build.outputs.RELEASE_BRANCH != ''
if: steps.commit-and-create-branch.outputs.pushed != ''
id: read-changelog
shell: bash
run: |
r=$(python3 ./.github/workflows/extract.py ./CHANGELOG.md ${{ steps.get-version.outputs.VERSION }}) # <--- Read Changelog.md
r="${r//'%'/'%25'}" # Multiline escape sequences for %
r="${r//$'\n'/'%0A'}" # Multiline escape sequences for '\n'
r="${r//$'\r'/'%0D'}" # Multiline escape sequences for '\r'
echo "CHANGELOG=$r" >> $GITHUB_OUTPUT
python3 ./.github/workflows/extract.py ./CHANGELOG.md ${{ steps.get-version.outputs.VERSION }} > 'body.md'
- name: Create Release
if: steps.create-release-branch-and-build.outputs.RELEASE_BRANCH != ''
if: steps.commit-and-create-branch.outputs.pushed != ''
id: create-release
uses: ncipollo/release-action@v1.13.0
with:
allowUpdates: true
body: ${{ steps.read-changelog.outputs.CHANGELOG }}
bodyFile: 'body.md'
tag: ${{ steps.get-version.outputs.RELEASE_VERSION }}
name: ${{ steps.get-version.outputs.RELEASE_INFO }}
token: ${{ secrets.GIT_TOKEN }}
makeLatest: true
artifacts: "dist/dash_extensions*,PKG-INFO"
replacesArtifacts: true
removeArtifacts: true
commit: ${{ steps.create-release-branch-and-build.outputs.RELEASE_BRANCH }}
commit: ${{ steps.commit-and-create-branch.outputs.commit_long_sha }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
__pycache__/
*.py[cod]
*$py.class
.DS_Store

# C extensions
*.so
Expand Down Expand Up @@ -134,4 +135,4 @@ dash_extensions/*
inst/*
**/file_system_backend/*
man/*
R/*
R/*
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ NB: The 1.0.0 version introduces a number of breaking changes, see documentation
## Donation

[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=Z9RXT5HVPK3B8&currency_code=DKK&source=url)

## Installing

* Only `release/{VERSION}` branches and `v{VERSION}` tags should be used for direct pip / poetry based install(s), installation(s) from branches that were not created by the `release` action will not work as they will be missing all the `webpack` generated files.

0 comments on commit dd491c5

Please sign in to comment.