Skip to content

Commit 5a378cd

Browse files
authored
Add release workflow (#1635)
* Add release workflow Signed-off-by: Yong Tang <yong.tang.github@outlook.com> * Add step to release to test.pypi.org Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
1 parent 23b9520 commit 5a378cd

File tree

3 files changed

+158
-17
lines changed

3 files changed

+158
-17
lines changed

.github/workflows/release.note.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Release Note
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
release-note:
10+
name: README.md
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
with:
15+
fetch-depth: 0
16+
- run: git tag
17+
- run: python3 tools/release/note_create.py
18+
- run: git diff
19+
- run: python3 tools/release/note_update.py
20+
- run: git diff
21+
- uses: peter-evans/create-pull-request@v3
22+
with:
23+
commit-message: Update RELEASE.md [bot]
24+
branch: bot-RELEASE.md
25+
delete-branch: true
26+
title: 'Update RELEASE.md [bot]'
27+
body: |
28+
README.md: auto-updated by .github/workflows/release.note.yml

.github/workflows/release.yml

Lines changed: 66 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,77 @@
1-
name: Release Bot
1+
name: Release
22

33
on:
4-
push:
5-
branches:
6-
- master
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "Version (e.g., v0.24.0)"
8+
required: true
9+
commit:
10+
description: "Commit (e.g., 92b44e1)"
11+
required: true
712

813
jobs:
914
release:
10-
name: README.md
15+
name: Release
1116
runs-on: ubuntu-latest
1217
steps:
1318
- uses: actions/checkout@v2
1419
with:
1520
fetch-depth: 0
16-
- run: git tag
17-
- run: python3 tools/release/note_create.py
18-
- run: git diff
19-
- run: python3 tools/release/note_update.py
20-
- run: git diff
21-
- uses: peter-evans/create-pull-request@v3
21+
- run: |
22+
set -x -e
23+
COMMIT=$(git rev-parse --quiet --verify ${{ github.event.inputs.commit }})
24+
if [[ "$(git tag -l ${{ github.event.inputs.version }})" == "${{ github.event.inputs.version }}" ]]; then
25+
echo "${{ github.event.inputs.version }} already released"
26+
exit 1
27+
fi
28+
VERSION=${{ github.event.inputs.version }}
29+
30+
docker pull tfsigio/candidate:${VERSION:1}
31+
docker create -it --name storage tfsigio/candidate:${VERSION:1} bash
32+
docker cp storage:/wheelhouse .
33+
docker cp storage:/wheelhouse.sha256 .
34+
docker cp storage:/wheelhouse.commit .
35+
docker cp storage:/wheelhouse.version .
36+
37+
sha256sum wheelhouse/*.whl | sort -u | diff wheelhouse.sha256 -
38+
mv wheelhouse dist
39+
40+
if [[ "${COMMIT}" != "$(cat wheelhouse.commit)" ]]; then
41+
echo "${COMMIT} != $(cat wheelhouse.commit)"
42+
exit 1
43+
fi
44+
if [[ "${VERSION}" != "v$(cat wheelhouse.version)" ]]; then
45+
echo "${VERSION} != v$(cat wheelhouse.version)"
46+
exit 1
47+
fi
48+
49+
python3 tools/release/note_take.py ${VERSION}
50+
51+
echo "::set-output name=tag::${VERSION}"
52+
echo "::set-output name=name::TensorFlow I/O ${VERSION:1}"
53+
echo "::set-output name=commit::${COMMIT}"
54+
id: info
55+
- run: |
56+
set -x -e
57+
echo ${{ steps.info.outputs.tag }}
58+
echo ${{ steps.info.outputs.name }}
59+
echo ${{ steps.info.outputs.commit }}
60+
cat CURRENT.md
61+
- uses: softprops/action-gh-release@v1
62+
with:
63+
body_path: CURRENT.md
64+
name: ${{ steps.info.outputs.name }}
65+
tag_name: ${{ steps.info.outputs.tag }}
66+
target_commitish: ${{ steps.info.outputs.commit }}
67+
draft: true
68+
- uses: pypa/gh-action-pypi-publish@master
2269
with:
23-
commit-message: Update RELEASE.md [bot]
24-
branch: bot-RELEASE.md
25-
delete-branch: true
26-
title: 'Update RELEASE.md [bot]'
27-
body: |
28-
README.md: auto-updated by .github/workflows/release.yml
70+
user: __token__
71+
password: ${{ secrets.TEST_PYPI_TOKEN }}
72+
repository_url: https://test.pypi.org/legacy/
73+
#- uses: pypa/gh-action-pypi-publish@master
74+
# with:
75+
# user: __token__
76+
# password: ${{ secrets.PYPI_TOKEN }}
77+

tools/release/note_take.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright 2022 The TensorFlow Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ==============================================================================
15+
import re
16+
import sys
17+
import pathlib
18+
import subprocess
19+
import textwrap
20+
21+
exec(pathlib.Path("tensorflow_io/python/ops/version_ops.py").read_text())
22+
23+
# the `version` variable is loaded from the `exec`` above
24+
if f"v{version}" != sys.argv[1]:
25+
print(f"[Version {version} in version_ops.py does not match {sys.argv[1]}]")
26+
sys.exit(1)
27+
version = sys.argv[1]
28+
29+
note = pathlib.Path("RELEASE.md").read_text()
30+
31+
entries = []
32+
for index, line in enumerate(note.split("\n")):
33+
if re.match(r"^# Release [\d\.]+", line):
34+
entries.append((line[len("# Release ") :].rstrip(), index))
35+
36+
tag = (
37+
subprocess.run(
38+
["git", "tag", "-l", f"v{entries[0][0]}"],
39+
capture_output=True,
40+
check=True,
41+
)
42+
.stdout.decode("utf-8")
43+
.strip()
44+
)
45+
if tag == f"v{entries[0][0]}":
46+
print(
47+
"[The latest version in RELEASE.md {} has already been released]".format(
48+
entries[0][0]
49+
)
50+
)
51+
sys.exit(0)
52+
53+
54+
if version != f"v{entries[0][0]}":
55+
print(
56+
"[The latest version in RELEASE.md {} has does not match {}]".format(
57+
entries[0][0], version
58+
)
59+
)
60+
sys.exit(0)
61+
62+
# Cut note
63+
current = "\n".join(note.split("\n")[: entries[1][1]])
64+
pathlib.Path("CURRENT.md").write_text(current)

0 commit comments

Comments
 (0)