Repository navigation
144 lines (129 loc) · 4.62 KB
/
Copy pathrelease.yml
File metadata and controls
144 lines (129 loc) · 4.62 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
134
135
136
137
138
139
140
141
142
143
144
# SPDX-License-Identifier: Apache-2.0
# Releases the SDK when a stable core pin lands on main: tag and draft release,
# build, publish to PyPI, then attach the files and publish the GitHub release.
# PyPI trusts this file, release.yml, in the pypi environment (trusted
# publishing), so the publish job needs no token. Pushed tags never trigger it.
name: release
on:
push:
branches: [main]
workflow_dispatch:
inputs:
sha:
description: Commit on main to release (default the tip); the pin there must be stable
required: false
default: ""
permissions:
contents: read
concurrency:
group: release
cancel-in-progress: false
jobs:
tag:
name: tag
# Only main releases, also when the workflow is started by hand.
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write # create the tag and the draft release
pull-requests: read # read the merged PR's body for the release notes
outputs:
tag: ${{ steps.tag.outputs.tag }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- id: tag
name: Tag the release and create a draft
env:
GH_TOKEN: ${{ github.token }}
EVENT: ${{ github.event_name }}
INPUT_SHA: ${{ inputs.sha }}
BEFORE: ${{ github.event.before }}
run: |
set -euo pipefail
if [ "$EVENT" = workflow_dispatch ]; then
sha=${INPUT_SHA:-$GITHUB_SHA}
git merge-base --is-ancestor "$sha" "$GITHUB_SHA" || {
echo "::error::$sha is not on main"
exit 1
}
scripts/release/tag-release.sh --force --sha "$sha" >>"$GITHUB_OUTPUT"
else
# Compare against the commit before the push, so a pin change
# that isn't the pushed tip still counts.
scripts/release/tag-release.sh --since "$BEFORE" >>"$GITHUB_OUTPUT"
fi
build:
name: build
needs: tag
if: needs.tag.outputs.tag != ''
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.tag.outputs.tag }}
persist-credentials: false
# No tool cache: what gets published is built from fresh downloads.
- uses: jdx/mise-action@e6a8b3978addb5a52f2b4cd9d91eafa7f0ab959d # v4.2.0
with:
cache: false
# Builds the wheel and sdist at the tag's version, verifies the wheel,
# and installs both on the oldest supported Python.
- name: Build
env:
TAG: ${{ needs.tag.outputs.tag }}
run: OPENSHELL_SDK_VERSION="${TAG#v}" mise run build
- name: Write checksums
run: (cd dist && sha256sum -- *) >openshell-checksums-sha256.txt
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: release
path: |
dist/
openshell-checksums-sha256.txt
if-no-files-found: error
publish-pypi:
name: publish-pypi
needs: [tag, build]
runs-on: ubuntu-latest
timeout-minutes: 10
environment:
name: pypi
url: https://pypi.org/project/openshell/
permissions:
id-token: write # trusted publishing to PyPI
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: release
path: release
- uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
with:
packages-dir: release/dist/
# Publishing comes last, so the release never shows without its files. If
# this job fails after PyPI accepted the upload, re-run only the failed jobs.
github-release:
name: github-release
needs: [tag, publish-pypi]
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write # attach the files and publish the release
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: release
path: release
- name: Attach the files and publish the release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.tag.outputs.tag }}
run: |
set -euo pipefail
gh release upload "$TAG" -R "$GITHUB_REPOSITORY" --clobber \
release/dist/* release/openshell-checksums-sha256.txt
gh release edit "$TAG" -R "$GITHUB_REPOSITORY" --draft=false --latest