-
Notifications
You must be signed in to change notification settings - Fork 0
129 lines (110 loc) · 5.16 KB
/
release-homebrew.yml
File metadata and controls
129 lines (110 loc) · 5.16 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
name: Sync Homebrew Tap
on:
push:
tags:
- 'cli/v*'
- 'crate/v*'
workflow_dispatch:
inputs:
jacs_version:
description: "JACS version for Formula/jacs.rb (defaults to tag or jacs/Cargo.toml)"
required: false
haisdk_version:
description: "HAISDK version for Formula/haisdk.rb (defaults to latest on PyPI)"
required: false
haisdk_pypi_package:
description: "PyPI package name for HAISDK"
required: false
default: "haisdk"
tap_repository:
description: "Homebrew tap repository (owner/repo)"
required: false
default: "HumanAssisted/homebrew-jacs"
tap_branch:
description: "Tap branch (stable branch is master)"
required: false
default: "master"
permissions:
contents: read
jobs:
sync-formulas:
if: ${{ secrets.HOMEBREW_TAP_TOKEN != '' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Resolve versions and artifact checksums
id: resolve
shell: bash
run: |
set -euo pipefail
ref_name="${GITHUB_REF_NAME:-}"
jacs_version_input="${{ github.event.inputs.jacs_version }}"
haisdk_version_input="${{ github.event.inputs.haisdk_version }}"
haisdk_pkg_input="${{ github.event.inputs.haisdk_pypi_package }}"
if [[ -n "${jacs_version_input}" ]]; then
jacs_version="${jacs_version_input}"
elif [[ "${ref_name}" =~ ^cli/v(.+)$ ]]; then
jacs_version="${BASH_REMATCH[1]}"
elif [[ "${ref_name}" =~ ^crate/v(.+)$ ]]; then
jacs_version="${BASH_REMATCH[1]}"
else
jacs_version="$(grep '^version = ' jacs/Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')"
fi
haisdk_pkg="${haisdk_pkg_input:-haisdk}"
if [[ -z "${haisdk_pkg}" ]]; then
haisdk_pkg="haisdk"
fi
pypi_json="$(mktemp)"
curl -fsSL "https://pypi.org/pypi/${haisdk_pkg}/json" -o "${pypi_json}"
if [[ -n "${haisdk_version_input}" ]]; then
haisdk_version="${haisdk_version_input}"
else
haisdk_version="$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1], encoding="utf-8"))["info"]["version"])' "${pypi_json}")"
fi
read -r haisdk_sdist_url haisdk_sha256 < <(python3 -c 'import json,sys; data=json.load(open(sys.argv[1], encoding="utf-8")); version=sys.argv[2]; entry=next((f for f in data.get("releases", {}).get(version, []) if f.get("packagetype")=="sdist"), None); (entry is not None) or sys.exit(f"No sdist found for version {version}"); print(entry["url"], entry["digests"]["sha256"])' "${pypi_json}" "${haisdk_version}")
jacs_crate="$(mktemp)"
curl -fsSL "https://crates.io/api/v1/crates/jacs/${jacs_version}/download" -o "${jacs_crate}"
jacs_sha256="$(sha256sum "${jacs_crate}" | awk '{print $1}')"
echo "jacs_version=${jacs_version}" >> "${GITHUB_OUTPUT}"
echo "jacs_sha256=${jacs_sha256}" >> "${GITHUB_OUTPUT}"
echo "haisdk_version=${haisdk_version}" >> "${GITHUB_OUTPUT}"
echo "haisdk_sdist_url=${haisdk_sdist_url}" >> "${GITHUB_OUTPUT}"
echo "haisdk_sha256=${haisdk_sha256}" >> "${GITHUB_OUTPUT}"
echo "haisdk_pypi_package=${haisdk_pkg}" >> "${GITHUB_OUTPUT}"
- name: Generate formula files
shell: bash
run: |
set -euo pipefail
mkdir -p generated/Formula
sed \
-e "s|__JACS_VERSION__|${{ steps.resolve.outputs.jacs_version }}|g" \
-e "s|__JACS_SHA256__|${{ steps.resolve.outputs.jacs_sha256 }}|g" \
.github/homebrew-templates/jacs.rb.tmpl > generated/Formula/jacs.rb
sed \
-e "s|__HAISDK_SDIST_URL__|${{ steps.resolve.outputs.haisdk_sdist_url }}|g" \
-e "s|__HAISDK_SHA256__|${{ steps.resolve.outputs.haisdk_sha256 }}|g" \
.github/homebrew-templates/haisdk.rb.tmpl > generated/Formula/haisdk.rb
- name: Checkout Homebrew tap repository
uses: actions/checkout@v4
with:
repository: ${{ github.event.inputs.tap_repository || 'HumanAssisted/homebrew-jacs' }}
ref: ${{ github.event.inputs.tap_branch || 'master' }}
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
path: tap
- name: Publish updated formulas to tap
shell: bash
run: |
set -euo pipefail
mkdir -p tap/Formula
cp generated/Formula/jacs.rb tap/Formula/jacs.rb
cp generated/Formula/haisdk.rb tap/Formula/haisdk.rb
cd tap
if git diff --quiet -- Formula/jacs.rb Formula/haisdk.rb; then
echo "No Homebrew formula changes to publish."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add Formula/jacs.rb Formula/haisdk.rb
git commit -m "Update formulas: jacs v${{ steps.resolve.outputs.jacs_version }}, haisdk v${{ steps.resolve.outputs.haisdk_version }}"
git push origin HEAD:${{ github.event.inputs.tap_branch || 'master' }}