Skip to content

Commit d6f759f

Browse files
committed
Merge branch 'release/v2.0.0'
2 parents a41a7c4 + 162945e commit d6f759f

File tree

8 files changed

+93
-23
lines changed

8 files changed

+93
-23
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: Checkout
12-
uses: actions/checkout@v3
12+
uses: actions/checkout@v5
1313

1414
- name: Release
15-
uses: lumynou5/github-release-action@v1
15+
uses: lumynou5/github-release-action@main
1616
with:
1717
token: ${{github.token}}

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file.
33

44
## [Unreleased]
55

6+
## [2.0.0] - 2025-10-30
7+
### Added
8+
- Uploading assets is supported now.
9+
### Changed
10+
- If the tag already exists, for example, the main branch is force pushed, now
11+
the action won't fail and the release will be updated.
12+
613
## [1.3.0] - 2024-12-24
714
### Added
815
- Output the changelog of last version.
@@ -23,7 +30,8 @@ All notable changes to this project will be documented in this file.
2330

2431
## [1.1.0] - 2023-05-05 [YANKED]
2532
### Added
26-
- Outputs the names of the Git tags of the release and the major version; i.e., the filled templates are outputed.
33+
- Outputs the names of the Git tags of the release and the major version; i.e.,
34+
the filled templates are outputed.
2735
- Input `major-tag-template` can be empty for no major tag now.
2836

2937
## [1.0.1] - 2023-05-01
@@ -34,6 +42,9 @@ All notable changes to this project will be documented in this file.
3442
### Added
3543
- First release.
3644

45+
[Unreleased]: https://github.com/lumynou5/github-release-action/compare/v2.0.0...develop
46+
[2.0.0]: https://github.com/lumynou5/github-release-action/releases/tag/v2.0.0
47+
[1.3.0]: https://github.com/lumynou5/github-release-action/releases/tag/v1.3.0
3748
[1.2.0]: https://github.com/lumynou5/github-release-action/releases/tag/v1.2.0
3849
[1.1.1]: https://github.com/lumynou5/github-release-action/releases/tag/v1.1.1
3950
[1.1.0]: https://github.com/lumynou5/github-release-action/releases/tag/v1.1.0

LICENSE.md renamed to LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2022-2024 Lumynous
3+
Copyright (c) 2022-2025 Lumynous
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ jobs:
1818
uses: actions/checkout@v3
1919

2020
- name: Release
21-
uses: lumynou5/github-release-action@v1
21+
uses: lumynou5/github-release-action@v2
2222
with:
2323
token: ${{github.token}}
24+
assets: |
25+
dist/linux-x86_64
26+
dist/windows.exe::windows version
27+
dist/darwin:macos
2428
```
2529
2630
In this example workflow, it'll create a release whenever push to `main` branch.
@@ -65,6 +69,13 @@ with:
6569
- `is-draft`
6670
If the GitHub release is a draft.
6771
Default: `false`.
72+
- `assets`
73+
A newline-separated list of files to upload. Besides file paths, it also
74+
accpets optional name and label (short description for the asset) separated by
75+
colons. For example, `path/to/file:name:label` renames the asset to `name`
76+
instead of using the basename of the file. The name can be omitted by leaving
77+
an empty string there (so two colons in a row) if you want to set label only.
78+
Default: empty.
6879

6980
The following list shows the parameters that can be used in templates. To use
7081
parameters, add a parameter name wrapping with braces to your template, and it

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ inputs:
3232
description: If the GitHub release is a draft.
3333
required: false
3434
default: 'false'
35+
assets:
36+
description: A newline-separated list of files to upload.
37+
required: false
38+
default: ''
3539
outputs:
3640
version:
3741
description: The version.

bump_version.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/bash
2+
3+
temp=$(mktemp)
4+
5+
sed -e "
6+
/## \[Unreleased\]/{
7+
G;
8+
a\
9+
## [$1] - $(date -I)
10+
}
11+
/\[Unreleased\]:/a\
12+
[$1]: https://github.com/lumynou5/github-release-action/releases/tag/v$1
13+
s/v[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\.\.\.develop/v$1...develop/
14+
" CHANGELOG.md >$temp
15+
16+
cat $temp >CHANGELOG.md
17+
rm $temp

main.py

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from os import environ as env
22
import keepachangelog
3-
from github import Github
3+
from github import Auth, Github, GithubException, UnknownObjectException
4+
from github.GithubObject import NotSet
45

56

67
class Data(dict):
@@ -17,8 +18,10 @@ def getLatestChange():
1718
return list(changes.values())[0]
1819

1920

20-
github = Github(base_url=env['GITHUB_API_URL'],
21-
login_or_token=env['INPUT_TOKEN'])
21+
github = Github(
22+
base_url=env['GITHUB_API_URL'],
23+
auth=Auth.Token(env['INPUT_TOKEN'])
24+
)
2225
repo = github.get_repo(env['GITHUB_REPOSITORY'])
2326

2427
change = getLatestChange()
@@ -35,32 +38,56 @@ def getLatestChange():
3538

3639
# Create release.
3740
data['tag'] = env['INPUT_TAG-TEMPLATE'].format_map(data)
38-
release = repo.create_git_release(
39-
data['tag'],
40-
env['INPUT_NAME-TEMPLATE'].format_map(data),
41-
data['change'],
42-
env['INPUT_IS-DRAFT'] == 'true',
43-
data['prerelease'] is not None,
44-
env['GITHUB_SHA'])
41+
try:
42+
release = repo.create_git_release(
43+
data['tag'],
44+
env['INPUT_NAME-TEMPLATE'].format_map(data),
45+
data['change'],
46+
env['INPUT_IS-DRAFT'] == 'true',
47+
data['prerelease'] is not None,
48+
target_commitish=env['GITHUB_SHA']
49+
)
50+
except GithubException as ex:
51+
if ex.status != 422:
52+
raise
53+
# If the tag already exists.
54+
release = repo.get_release(data['tag'])
55+
release.update_release(
56+
env['INPUT_NAME-TEMPLATE'].format_map(data),
57+
data['change'],
58+
target_commitish=env['GITHUB_SHA']
59+
)
60+
for asset in release.get_assets():
61+
asset.delete_asset()
62+
63+
# Upload assets.
64+
for entry in env['INPUT_ASSETS'].splitlines():
65+
path, _, rest = entry.partition(':')
66+
name, _, label = rest.partition(':')
67+
release.upload_asset(
68+
path,
69+
name=name if name != '' else NotSet,
70+
label=label
71+
)
4572

4673
# Move major tag.
4774
if env['INPUT_MAJOR-TAG-TEMPLATE'] != '' and data['major'] != 0:
4875
data['major_tag'] = env['INPUT_MAJOR-TAG-TEMPLATE'].format_map(data)
49-
major = repo.get_git_ref(f'tags/{data["major_tag"]}')
50-
if major.ref is not None:
76+
try:
77+
major = repo.get_git_ref(f'tags/{data["major_tag"]}')
5178
major.edit(env['GITHUB_SHA'])
52-
else:
79+
except UnknownObjectException:
5380
repo.create_git_ref(f'refs/tags/{data["major_tag"]}', env['GITHUB_SHA'])
5481
else:
5582
data['major_tag'] = ''
5683

5784
# Move minor tag.
5885
if env['INPUT_MINOR-TAG-TEMPLATE'] != '':
5986
data['minor_tag'] = env['INPUT_MINOR-TAG-TEMPLATE'].format_map(data)
60-
minor = repo.get_git_ref(f'tags/{data["minor_tag"]}')
61-
if minor.ref is not None:
87+
try:
88+
minor = repo.get_git_ref(f'tags/{data["minor_tag"]}')
6289
minor.edit(env['GITHUB_SHA'])
63-
else:
90+
except UnknownObjectException:
6491
repo.create_git_ref(f'refs/tags/{data["minor_tag"]}', env['GITHUB_SHA'])
6592
else:
6693
data['minor_tag'] = ''

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
keepachangelog==2.0.0.dev5
2-
PyGithub==1.58.0
1+
keepachangelog==2.0.0
2+
PyGithub==2.8.1

0 commit comments

Comments
 (0)