-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (91 loc) · 2.93 KB
/
release.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
name: Build and Create Release
permissions:
contents: write
on:
workflow_dispatch:
inputs:
version:
description: 'Version in SemVer format'
type: string
required: true
description:
description: 'Description of the release'
type: string
required: true
latest:
description: 'Is this the latest release?'
required: false
type: boolean
default: true
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Increase version
run: |
VERSION=${VERSION#v}
echo "VERSION=$VERSION" >> $GITHUB_ENV
sed -i "s/__version__ = .*/__version__ = '${VERSION}'/" hackPyrateBus/__init__.py
sed -i "s/version = .*/version = '${VERSION}',/" setup.py
env:
VERSION: ${{ inputs.version }}
- name: Commit and push changes
run: |
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Action"
git add setup.py hackPyrateBus/__init__.py
if git diff-index --quiet HEAD --; then
echo "No changes to commit"
else
git commit -m "all: bump version to $VERSION"
git push origin HEAD
fi
env:
VERSION: ${{ env.VERSION }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Create Release and Upload Assets
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
const tag = context.payload.inputs.version;
const repo = process.env.GITHUB_REPOSITORY;
const [owner, repoName] = repo.split('/');
// Get the current branch name
const branch = process.env.GITHUB_REF.replace('refs/heads/', '');
payload = {
owner: owner,
repo: repoName,
tag_name: tag,
name: `Release ${tag}`,
target_commitish: branch,
generate_release_notes: true,
make_latest: context.payload.inputs.latest,
};
console.log(payload);
const releaseResponse = await github.rest.repos.createRelease(payload);
const { id: id } = releaseResponse.data;
globber = await glob.create('dist/*');
const files = await globber.glob();
for (const file of files) {
const content = fs.readFileSync(file);
const name = path.basename(file);
await github.rest.repos.uploadReleaseAsset({
name: name,
owner: owner,
repo: repoName,
release_id: id,
data: content,
});
}