Skip to content

Commit

Permalink
Add workflow to build and release
Browse files Browse the repository at this point in the history
  • Loading branch information
ljodal committed Jul 6, 2022
1 parent de68ed8 commit 2bd2525
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ jobs:
linter: ["isort", "black", "mypy", "flake8"]
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: true
uses: actions/checkout@v3
- name: Setup project
uses: ./.github/actions/setup-project
- name: Add problem matcher
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Workflow to build and release a new version
name: Release to PyPI

on:
push:
tags:
- 'v*'

jobs:
build-and-release:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup project
uses: ./.github/actions/setup-project
- name: Build package
run: poetry build
# - name: Publish package to PyPI
# run: poetry publish --username=__token__ --password="${{ secrets.PYPI_API_TOKEN }}"
- name: Create GitHub release
uses: actions/github-script@v6
with:
script: |
const fs = require("fs");
const tagName = context.ref.replace(/^refs\/tags\//, '');
const release = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tagName,
name: `Release ${tagName}`,
});
if (release.status < 200 || release.status >= 300) {
core.setFailed(`Could not create release for tag '${tagName}'`);
return;
}
async function uploadBuild(filename) {
const filepath = `./dist/${filename}`;
const response = await github.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.data.id,
name: filename,
data: fs.readFileSync(filepath),
});
return response.status >= 200 && response.status < 300;
}
const results = fs.readdirSync('./dist').map(uploadBuild);
const allUploaded = results.reduce((previous, current) => previous && current, true);
if (!allUploaded) {
core.setFailed(`Count not upload release assets for tag '${tagName}'`);
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ __pycache__
*.pyc
.envrc
.venv
dist

0 comments on commit 2bd2525

Please sign in to comment.