Repository navigation
167 lines (159 loc) · 5.73 KB
/
Copy pathrelease.yml
File metadata and controls
167 lines (159 loc) · 5.73 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
name: Release
# Every push to main updates a release PR (version bump and CHANGELOG from the
# Conventional Commits since the last release). Merging that PR tags the release,
# publishes the package to npm and points the Homebrew formula at it, with no
# manual step. Run it by hand with a tag to finish a release that stopped halfway;
# whatever already went out is left as it is.
on:
push:
branches: [main]
workflow_dispatch:
inputs:
tag:
description: Release tag to publish again, such as v2.2.5
required: true
permissions:
contents: read
concurrency:
group: release
cancel-in-progress: false
jobs:
release-please:
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
outputs:
release_created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
steps:
- id: release
uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0
with:
config-file: release-please-config.json
manifest-file: .release-please-manifest.json
publish-npm:
needs: release-please
if: >-
always() && (
needs.release-please.outputs.release_created == 'true' ||
github.event_name == 'workflow_dispatch'
)
runs-on: ubuntu-latest
timeout-minutes: 20
permissions:
contents: read
id-token: write
env:
TAG: ${{ needs.release-please.outputs.tag_name || inputs.tag }}
outputs:
version: ${{ steps.pack.outputs.version }}
sha256: ${{ steps.pack.outputs.sha256 }}
published: ${{ steps.publish.outputs.published }}
steps:
- uses: actions/checkout@v6
with:
ref: ${{ env.TAG }}
- uses: actions/setup-node@v6
with:
node-version: 24
registry-url: https://registry.npmjs.org
package-manager-cache: false
- run: npm ci
- run: npm test
- name: Pack
id: pack
run: |
VERSION="$(node -p "require('./package.json').version")"
if [ "v$VERSION" != "$TAG" ]; then
echo "::error::Tag $TAG does not match package.json $VERSION"
exit 1
fi
# The prepare script prints to stdout, so take the tarball from its own directory.
mkdir "$RUNNER_TEMP/pack"
npm pack --pack-destination "$RUNNER_TEMP/pack" >/dev/null
FILE="$(ls "$RUNNER_TEMP/pack"/*.tgz)"
{
echo "version=$VERSION"
echo "file=$FILE"
echo "sha256=$(sha256sum "$FILE" | cut -d' ' -f1)"
} >> "$GITHUB_OUTPUT"
- name: Publish
id: publish
env:
VERSION: ${{ steps.pack.outputs.version }}
FILE: ${{ steps.pack.outputs.file }}
run: |
if npm view "@kfastov/tgcli@$VERSION" version >/dev/null 2>&1; then
echo "$VERSION is on npm already."
echo "published=false" >> "$GITHUB_OUTPUT"
else
# Trusted publishing: npm takes the workflow's OIDC token, no secret.
npm publish "$FILE" --access public --provenance
echo "published=true" >> "$GITHUB_OUTPUT"
fi
update-brew:
needs: publish-npm
if: always() && needs.publish-npm.result == 'success'
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
env:
HOMEBREW_TAP_SSH_KEY: ${{ secrets.HOMEBREW_TAP_SSH_KEY }}
VERSION: ${{ needs.publish-npm.outputs.version }}
steps:
- name: Skip if no Homebrew deploy key
if: env.HOMEBREW_TAP_SSH_KEY == ''
run: echo "HOMEBREW_TAP_SSH_KEY not set; skipping brew update."
- name: Resolve tarball and checksum
if: env.HOMEBREW_TAP_SSH_KEY != ''
env:
PUBLISHED: ${{ needs.publish-npm.outputs.published }}
PACKED_SHA256: ${{ needs.publish-npm.outputs.sha256 }}
run: |
TARBALL_URL="https://registry.npmjs.org/@kfastov/tgcli/-/tgcli-${VERSION}.tgz"
if [ "$PUBLISHED" = "true" ]; then
# The bytes just published. npm can take minutes to serve them, and
# the formula only needs their checksum.
SHA256="$PACKED_SHA256"
else
curl -fsSL --retry 10 --retry-delay 15 --retry-all-errors "$TARBALL_URL" -o tgcli.tgz
SHA256="$(sha256sum tgcli.tgz | cut -d' ' -f1)"
fi
echo "TARBALL_URL=$TARBALL_URL" >> "$GITHUB_ENV"
echo "SHA256=$SHA256" >> "$GITHUB_ENV"
- uses: actions/checkout@v6
if: env.HOMEBREW_TAP_SSH_KEY != ''
with:
repository: kfastov/homebrew-tap
ssh-key: ${{ secrets.HOMEBREW_TAP_SSH_KEY }}
path: homebrew-tap
- name: Update formula
if: env.HOMEBREW_TAP_SSH_KEY != ''
env:
FORMULA_PATH: homebrew-tap/Formula/tgcli.rb
run: |
python - <<'PY'
import os
import pathlib
import re
path = pathlib.Path(os.environ["FORMULA_PATH"])
text = path.read_text()
url = os.environ["TARBALL_URL"]
sha = os.environ["SHA256"]
text = re.sub(r'^(\s*url\s+\").*(\")', r'\g<1>%s\g<2>' % url, text, flags=re.M)
text = re.sub(r'^(\s*sha256\s+\").*(\")', r'\g<1>%s\g<2>' % sha, text, flags=re.M)
path.write_text(text)
PY
- name: Commit and push
if: env.HOMEBREW_TAP_SSH_KEY != ''
run: |
cd homebrew-tap
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Formula/tgcli.rb
git commit -m "chore(brew): bump tgcli to ${VERSION}" || exit 0
git push