Repository navigation
133 lines (124 loc) · 4.33 KB
/
Copy pathrelease.yml
File metadata and controls
133 lines (124 loc) · 4.33 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: Release
# Manual only: Actions > Release > Run workflow, on master.
# Publishes the version in PyImageLabeling/version.json: bump it first, and
# add its "## <version>" section to CHANGELOG.md (the GitHub release text).
#
# version -> build + tests (3 OS each) + Windows exe
# -> PyPI (the Linux-built wheel and sdist)
# -> GitHub release vX.Y.Z (the exe only, so the README's
# "exe downloads" badge counts exe downloads)
#
# PyPI cannot be undone (a version number can never be reused), so it only
# runs once every build, test and the exe have passed. "dry_run" (on by
# default) runs everything but the two publishing jobs.
#
# PyPI side, once: project > Settings > Publishing > add a GitHub publisher
# (owner crillab, repository PyImageLabeling, workflow release.yml,
# environment pypi). No token is stored anywhere.
on:
workflow_dispatch:
inputs:
dry_run:
description: "Dry run: build and test, publish nothing"
type: boolean
default: true
permissions:
contents: read
concurrency:
group: release
jobs:
version:
name: Check the version is new
runs-on: ubuntu-latest
outputs:
version: ${{ steps.read.outputs.version }}
steps:
- uses: actions/checkout@v5
- id: read
env:
DRY_RUN: ${{ inputs.dry_run }}
run: |
if [ "$GITHUB_REF" != "refs/heads/master" ]; then
echo "::error::release from master only, not $GITHUB_REF"
exit 1
fi
version=$(python3 -c "import json; print(json.load(open('PyImageLabeling/version.json'))['version'])")
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "Version: $version"
problems=""
if curl -sf -o /dev/null "https://pypi.org/pypi/PyImageLabeling/$version/json"; then
problems="$version is already on PyPI"
fi
if git ls-remote --exit-code --tags origin "refs/tags/v$version" > /dev/null; then
problems="$problems${problems:+; }tag v$version already exists"
fi
if [ -z "$(.github/scripts/release_notes.sh "$version")" ]; then
problems="$problems${problems:+; }no \"## $version\" section in CHANGELOG.md"
fi
if [ -n "$problems" ]; then
if [ "$DRY_RUN" = "true" ]; then
echo "::warning::$problems (fine for a dry run; fix before releasing)"
else
echo "::error::$problems (bump PyImageLabeling/version.json, describe it in CHANGELOG.md)"
exit 1
fi
fi
build:
needs: version
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
uses: ./.github/workflows/reusable-build.yml
with:
os: ${{ matrix.os }}
tests:
needs: version
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
uses: ./.github/workflows/reusable-tests.yml
with:
os: ${{ matrix.os }}
exe:
needs: version
uses: ./.github/workflows/exe.yml
pypi:
name: Publish to PyPI
if: ${{ !inputs.dry_run }}
needs: [version, build, tests, exe]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/PyImageLabeling/${{ needs.version.outputs.version }}/
permissions:
id-token: write # Trusted Publishing
steps:
- uses: actions/download-artifact@v8
with:
name: dist-ubuntu-latest
path: dist
- uses: pypa/gh-action-pypi-publish@release/v1
github-release:
name: GitHub release
if: ${{ !inputs.dry_run }}
needs: [version, pypi]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v5
- uses: actions/download-artifact@v8
with:
name: exe
path: exe
- env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.version.outputs.version }}
run: |
.github/scripts/release_notes.sh "$VERSION" > notes.md
printf '\nInstall or upgrade: `pip install -U PyImageLabeling` (https://pypi.org/project/PyImageLabeling/%s/)\n' \
"$VERSION" >> notes.md
gh release create "v$VERSION" exe/*.exe \
--repo "$GITHUB_REPOSITORY" --target "$GITHUB_SHA" \
--title "PyImageLabeling $VERSION" --notes-file notes.md