Skip to content

Commit 5456496

Browse files
committed
Add CI/CD, install script, and fix argc dependency
- argc: link:../argc → github:ethan-huo/argc - Add build/check/typecheck scripts - Add CI workflow (push/PR → bun run check) - Add release workflow (version bump → tag + GitHub Release) - Add install.sh for curl-pipe-bash installation - Fix argc link in README, add script install option
1 parent baed13a commit 5456496

7 files changed

Lines changed: 181 additions & 6 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
check:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v6.0.2
17+
- uses: oven-sh/setup-bun@v2.2.0
18+
with:
19+
bun-version: latest
20+
- run: bun install --frozen-lockfile
21+
- run: bun run check

‎.github/workflows/release.yml‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
detect-version-bump:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
outputs:
13+
should_release: ${{ steps.version.outputs.should_release }}
14+
version: ${{ steps.version.outputs.version }}
15+
tag: ${{ steps.version.outputs.tag }}
16+
steps:
17+
- uses: actions/checkout@v6.0.2
18+
with:
19+
fetch-depth: 0
20+
- id: version
21+
shell: bash
22+
run: |
23+
set -euo pipefail
24+
25+
current_version=$(jq -r '.version' package.json)
26+
before_sha="${{ github.event.before }}"
27+
previous_version=""
28+
29+
if [ "$before_sha" != "0000000000000000000000000000000000000000" ] \
30+
&& git cat-file -e "${before_sha}:package.json" 2>/dev/null; then
31+
previous_version=$(git show "${before_sha}:package.json" | jq -r '.version')
32+
fi
33+
34+
should_release=false
35+
if [ -z "$previous_version" ] || [ "$current_version" != "$previous_version" ]; then
36+
should_release=true
37+
fi
38+
39+
echo "Detected package version: $current_version"
40+
echo "Previous package version: ${previous_version:-<none>}"
41+
echo "Release required: $should_release"
42+
43+
{
44+
echo "should_release=$should_release"
45+
echo "version=$current_version"
46+
echo "tag=v$current_version"
47+
} >> "$GITHUB_OUTPUT"
48+
49+
release:
50+
needs: detect-version-bump
51+
if: needs.detect-version-bump.outputs.should_release == 'true'
52+
runs-on: ubuntu-latest
53+
permissions:
54+
contents: write
55+
steps:
56+
- uses: actions/checkout@v6.0.2
57+
with:
58+
fetch-depth: 0
59+
- uses: oven-sh/setup-bun@v2.2.0
60+
with:
61+
bun-version: latest
62+
- run: bun install --frozen-lockfile
63+
- run: bun run check
64+
- run: bun run build
65+
- run: tar -czf dist/apple-docs.tar.gz -C dist apple-docs
66+
- name: Ensure release tag exists for the current package version
67+
env:
68+
TAG: ${{ needs.detect-version-bump.outputs.tag }}
69+
shell: bash
70+
run: |
71+
set -euo pipefail
72+
73+
git fetch --tags origin
74+
75+
if git ls-remote --exit-code --tags origin "refs/tags/$TAG" >/dev/null 2>&1; then
76+
git fetch origin "refs/tags/$TAG:refs/tags/$TAG"
77+
tag_sha=$(git rev-list -n 1 "$TAG")
78+
if [ "$tag_sha" != "$GITHUB_SHA" ]; then
79+
echo "Tag $TAG already exists on $tag_sha, not on $GITHUB_SHA."
80+
exit 1
81+
fi
82+
exit 0
83+
fi
84+
85+
git config user.name "github-actions[bot]"
86+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
87+
git tag "$TAG" "$GITHUB_SHA"
88+
git push origin "refs/tags/$TAG"
89+
- name: Create or update GitHub Release
90+
env:
91+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92+
TAG: ${{ needs.detect-version-bump.outputs.tag }}
93+
shell: bash
94+
run: |
95+
set -euo pipefail
96+
97+
if gh release view "$TAG" >/dev/null 2>&1; then
98+
gh release upload "$TAG" dist/apple-docs.tar.gz --clobber
99+
exit 0
100+
fi
101+
102+
gh release create "$TAG" dist/apple-docs.tar.gz \
103+
--generate-notes \
104+
--target "$GITHUB_SHA" \
105+
--title "$TAG"

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules/
2+
dist/

‎README.md‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ AI coding agents working with Apple frameworks need fast access to API docs, sym
99
## Install
1010

1111
```bash
12-
# requires: bun
12+
curl -fsSL https://raw.githubusercontent.com/ethan-huo/apple-docs/main/install.sh | bash
13+
```
14+
15+
Or with Bun:
16+
17+
```bash
1318
bun install -g github:ethan-huo/apple-docs
1419
```
1520

@@ -79,7 +84,7 @@ All output is Markdown.
7984

8085
## Built With
8186

82-
- [argc](https://github.com/user/argc) — schema-first CLI framework for Bun
87+
- [argc](https://github.com/ethan-huo/argc) — schema-first CLI framework for Bun
8388
- [cheerio](https://cheerio.js.org/) — HTML parsing for search results
8489
- [Bun](https://bun.sh/) — runtime (no build step, runs TypeScript directly)
8590

‎bun.lock‎

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎install.sh‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
# Install apple-docs CLI from the latest GitHub release.
3+
# Usage: curl -fsSL https://raw.githubusercontent.com/ethan-huo/apple-docs/main/install.sh | bash
4+
set -euo pipefail
5+
6+
REPO="ethan-huo/apple-docs"
7+
INSTALL_DIR="${APPLE_DOCS_INSTALL_DIR:-$HOME/.local/bin}"
8+
9+
# Resolve version — accept explicit arg or fetch latest tag.
10+
if [ "${1:-}" != "" ]; then
11+
tag="v${1#v}"
12+
else
13+
tag=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" \
14+
| grep '"tag_name"' | head -1 | cut -d '"' -f 4)
15+
fi
16+
17+
if [ -z "$tag" ]; then
18+
echo "error: failed to resolve release tag" >&2
19+
exit 1
20+
fi
21+
22+
url="https://github.com/$REPO/releases/download/$tag/apple-docs.tar.gz"
23+
echo "Installing apple-docs $tag to $INSTALL_DIR ..."
24+
25+
mkdir -p "$INSTALL_DIR"
26+
curl -fsSL "$url" | tar -xz -C "$INSTALL_DIR"
27+
28+
if ! command -v bun >/dev/null 2>&1; then
29+
echo "bun runtime not found — installing ..."
30+
curl -fsSL https://bun.sh/install | bash
31+
fi
32+
33+
case ":$PATH:" in
34+
*":$INSTALL_DIR:"*) ;;
35+
*) echo "hint: add $INSTALL_DIR to your PATH if it is not already" ;;
36+
esac
37+
38+
echo "done: $(command -v apple-docs 2>/dev/null || echo "$INSTALL_DIR/apple-docs")"

‎package.json‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
},
99
"scripts": {
1010
"dev": "bun run src/cli.ts",
11-
"test": "bun test"
11+
"typecheck": "bunx tsc --noEmit",
12+
"test": "bun test",
13+
"check": "bun run typecheck && bun test",
14+
"build": "bun build src/cli.ts --outfile=dist/apple-docs --target=bun --minify && chmod +x dist/apple-docs"
1215
},
1316
"dependencies": {
14-
"argc": "link:../argc",
17+
"argc": "github:ethan-huo/argc",
1518
"cheerio": "^1.1.0"
1619
},
1720
"devDependencies": {

0 commit comments

Comments
 (0)