Skip to content

Commit ea0fb52

Browse files
authored
Merge pull request #16 from thetnaingtn/refactor
Refactor
2 parents 60aca93 + 7ae3813 commit ea0fb52

File tree

8 files changed

+190
-287
lines changed

8 files changed

+190
-287
lines changed

.github/workflows/release.yml

+109-15
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,130 @@
1-
name: goreleaser
1+
name: Release
22

33
on:
44
push:
55
tags:
6-
- "*"
7-
8-
permissions:
9-
contents: write
6+
- "v*.*.*"
7+
workflow_dispatch:
108

119
jobs:
1210
goreleaser:
1311
runs-on: ubuntu-latest
1412
steps:
15-
-
16-
name: Checkout
13+
- name: Checkout
1714
uses: actions/checkout@v2
1815
with:
1916
fetch-depth: 0
20-
-
21-
name: Fetch all tags
17+
18+
- name: Fetch all tags
2219
run: git fetch --force --tags
23-
-
24-
name: Set up Go
20+
21+
- name: Set up Go
2522
uses: actions/setup-go@v2
2623
with:
2724
go-version: 1.18
28-
-
29-
name: Run GoReleaser
25+
26+
- name: Run GoReleaser
3027
uses: goreleaser/goreleaser-action@v2
3128
with:
3229
distribution: goreleaser
33-
version: ${{ env.GITHUB_REF_NAME }}
34-
args: release --rm-dist
30+
version: latest
31+
args: release --clean
3532
env:
3633
GITHUB_TOKEN: ${{ secrets.PUBLISHER_TOKEN }}
34+
35+
- name: Upload binaries
36+
uses: actions/upload-artifact
37+
with:
38+
path: |
39+
dist
40+
!homebrew
41+
!dist/**/*.tar.gz
42+
!dist/**/*.zip
43+
!dist/**/*.json
44+
!dist/**/*.yaml
45+
!dist/**/*.txt
46+
47+
publish-binaries:
48+
needs: goreleaser
49+
strategy:
50+
matrix:
51+
os: ["forky_darwin_amd64_v1","forky_darwin_arm64","forky_linux_amd64_v1","forky_linux_arm64","forky_windows_amd64_v1", "forky_windows_arm64"]
52+
runs-on: ubuntu-latest
53+
name: Publish binaries for different architectures and platforms to NPM
54+
steps:
55+
- name: Checkout
56+
uses: actions/checkout@v4
57+
with:
58+
fetch-depth: 0
59+
60+
- name: Install Node
61+
uses: actions/setup-node@v4
62+
with:
63+
node-version: "16"
64+
registry-url: "https://registry.npmjs.org"
65+
66+
- name: Download uploaded binaries
67+
uses: actions/download-artifact@v4
68+
with:
69+
name: binaries
70+
71+
- name: Set the release version
72+
shell: bash
73+
run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV
74+
75+
- name: Publish to NPM
76+
shell: bash
77+
run: |
78+
cd npm
79+
bin="forky"
80+
version="${{ env.RELEASE_VERSION }}"
81+
export version
82+
node_os=$(echo "${{ matrix.os }}" | cut -d "_" -f2)
83+
export node_os
84+
node_arch=$(echo "${{ matrix.os }}" | cut -d "_" -f3)
85+
export node_arch
86+
if [ "${node_os}" = "windows" ]; then
87+
export node_pkg="${bin}-windows-${node_arch}"
88+
else
89+
export node_pkg="${bin}-${node_os}-${node_arch}"
90+
fi
91+
mkdir -p "${node_pkg}/bin"
92+
envsubst < package.json.tmpl > "${node_pkg}/package.json"
93+
if [ "${node_os}" = "windows" ]; then
94+
bin="${bin}.exe"
95+
fi
96+
pwd
97+
install -D ../${{ matrix.os }}/${bin} ${node_pkg}/bin/${bin}
98+
cd "${node_pkg}"
99+
npm publish --access public
100+
env:
101+
NODE_AUTH_TOKEN: ${{secrets.NPM_API_KEY}}
102+
103+
publish-npm:
104+
needs: publish-binaries
105+
name: Publish base package to NPM
106+
runs-on: ubuntu-latest
107+
permissions:
108+
contents: write
109+
steps:
110+
- name: Checkout
111+
uses: actions/checkout@v4
112+
113+
- name: Set the release version
114+
shell: bash
115+
run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV
116+
117+
- name: Install Node
118+
uses: actions/setup-node@v4
119+
with:
120+
node-version: "16"
121+
registry-url: "https://registry.npmjs.org"
122+
- name: Publish to NPM
123+
shell: bash
124+
run: |
125+
cd npm/forky
126+
yarn install
127+
yarn build
128+
npm publish --access public
129+
env:
130+
NODE_AUTH_TOKEN: ${{secrets.NPM_API_KEY}}

npm/forky/package.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "forkyy",
3+
"version": "0.6.2",
4+
"bin": "lib/index.js",
5+
"description": "Synchronize your forks with ease",
6+
"repository": {
7+
"type": "git",
8+
"url": "git+https://github.com/thetnaingtn/forky.git"
9+
},
10+
"keywords": ["github","go", "cli", "synchronize", "sync", "bubble", "bubbletea","github-api", "fork"],
11+
"license": "MIT OR Apache-2.0",
12+
"homepage": "https://github.com/thetnaingtn/forky#readme",
13+
"scripts": {
14+
"typecheck": "tsc --noEmit",
15+
"lint": "eslint .",
16+
"lint:fix": "eslint . --fix",
17+
"build": "tsc",
18+
"dev": "yarn build && node lib/index.js"
19+
},
20+
"devDependencies": {
21+
"@types/node": "^18.19.3",
22+
"@typescript-eslint/eslint-plugin": "^5.48.0",
23+
"@typescript-eslint/parser": "^5.48.0",
24+
"eslint": "^8.31.0",
25+
"typescript": "^4.9.4"
26+
},
27+
"optionalDependencies": {
28+
"forky-darwin-arm64": "0.6.2",
29+
"forky-darwin-amd64": "0.6.2",
30+
"forky-linux-arm64": "0.6.2",
31+
"forky-linux-amd64": "0.6.2",
32+
"forky-windows-arm64": "0.6.2",
33+
"forky-windows-amd64": "0.6.2"
34+
}
35+
}

npm/forky/src/index.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env node
2+
3+
import { spawnSync } from "child_process"
4+
5+
function getExePath() {
6+
const arch = process.arch;
7+
let os = process.platform as string;
8+
let extension = '';
9+
if (['win32', 'cygwin'].includes(process.platform)) {
10+
os = 'windows';
11+
extension = '.exe';
12+
}
13+
14+
try {
15+
// Since the bin will be located inside `node_modules`, we can simply call require.resolve
16+
return require.resolve(`forky-${os}-${arch}/bin/forky${extension}`)
17+
} catch (e) {
18+
throw new Error(`Couldn't find forky binary inside node_modules for ${os}-${arch}`)
19+
}
20+
}
21+
22+
function runForky() {
23+
const args = process.argv.slice(2)
24+
const processResult = spawnSync(getExePath(), args, { stdio: "inherit" })
25+
process.exit(processResult.status ?? 0)
26+
}
27+
28+
runForky()

npm/forky/tsconfig.json

Whitespace-only changes.

npm/package.json.tmpl

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "${node_pkg}",
3+
"version": "${version}",
4+
"description": "Synchronize your forks with ease",
5+
"repository": {
6+
"type": "git",
7+
"url": "git+https://github.com/thetnaingtn/forky.git"
8+
},
9+
"keywords": ["github","go", "cli", "synchronize", "sync", "bubble", "bubbletea","github-api", "fork"],
10+
"license": "MIT OR Apache-2.0",
11+
"homepage": "https://github.com/thetnaingtn/forky#readme",
12+
"os": [
13+
"${node_os}"
14+
],
15+
"cpu": [
16+
"${node_arch}"
17+
]
18+
}

package-lock.json

-35
This file was deleted.

package.json

-32
This file was deleted.

0 commit comments

Comments
 (0)