Skip to content

Commit

Permalink
Merge pull request #16 from thetnaingtn/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
thetnaingtn authored Dec 24, 2023
2 parents 60aca93 + 7ae3813 commit ea0fb52
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 287 deletions.
124 changes: 109 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,130 @@
name: goreleaser
name: Release

on:
push:
tags:
- "*"

permissions:
contents: write
- "v*.*.*"
workflow_dispatch:

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Fetch all tags

- name: Fetch all tags
run: git fetch --force --tags
-
name: Set up Go

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18
-
name: Run GoReleaser

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: ${{ env.GITHUB_REF_NAME }}
args: release --rm-dist
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.PUBLISHER_TOKEN }}

- name: Upload binaries
uses: actions/upload-artifact
with:
path: |
dist
!homebrew
!dist/**/*.tar.gz
!dist/**/*.zip
!dist/**/*.json
!dist/**/*.yaml
!dist/**/*.txt
publish-binaries:
needs: goreleaser
strategy:
matrix:
os: ["forky_darwin_amd64_v1","forky_darwin_arm64","forky_linux_amd64_v1","forky_linux_arm64","forky_windows_amd64_v1", "forky_windows_arm64"]
runs-on: ubuntu-latest
name: Publish binaries for different architectures and platforms to NPM
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Node
uses: actions/setup-node@v4
with:
node-version: "16"
registry-url: "https://registry.npmjs.org"

- name: Download uploaded binaries
uses: actions/download-artifact@v4
with:
name: binaries

- name: Set the release version
shell: bash
run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV

- name: Publish to NPM
shell: bash
run: |
cd npm
bin="forky"
version="${{ env.RELEASE_VERSION }}"
export version
node_os=$(echo "${{ matrix.os }}" | cut -d "_" -f2)
export node_os
node_arch=$(echo "${{ matrix.os }}" | cut -d "_" -f3)
export node_arch
if [ "${node_os}" = "windows" ]; then
export node_pkg="${bin}-windows-${node_arch}"
else
export node_pkg="${bin}-${node_os}-${node_arch}"
fi
mkdir -p "${node_pkg}/bin"
envsubst < package.json.tmpl > "${node_pkg}/package.json"
if [ "${node_os}" = "windows" ]; then
bin="${bin}.exe"
fi
pwd
install -D ../${{ matrix.os }}/${bin} ${node_pkg}/bin/${bin}
cd "${node_pkg}"
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_API_KEY}}

publish-npm:
needs: publish-binaries
name: Publish base package to NPM
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set the release version
shell: bash
run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV

- name: Install Node
uses: actions/setup-node@v4
with:
node-version: "16"
registry-url: "https://registry.npmjs.org"
- name: Publish to NPM
shell: bash
run: |
cd npm/forky
yarn install
yarn build
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_API_KEY}}
35 changes: 35 additions & 0 deletions npm/forky/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "forkyy",
"version": "0.6.2",
"bin": "lib/index.js",
"description": "Synchronize your forks with ease",
"repository": {
"type": "git",
"url": "git+https://github.com/thetnaingtn/forky.git"
},
"keywords": ["github","go", "cli", "synchronize", "sync", "bubble", "bubbletea","github-api", "fork"],
"license": "MIT OR Apache-2.0",
"homepage": "https://github.com/thetnaingtn/forky#readme",
"scripts": {
"typecheck": "tsc --noEmit",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"build": "tsc",
"dev": "yarn build && node lib/index.js"
},
"devDependencies": {
"@types/node": "^18.19.3",
"@typescript-eslint/eslint-plugin": "^5.48.0",
"@typescript-eslint/parser": "^5.48.0",
"eslint": "^8.31.0",
"typescript": "^4.9.4"
},
"optionalDependencies": {
"forky-darwin-arm64": "0.6.2",
"forky-darwin-amd64": "0.6.2",
"forky-linux-arm64": "0.6.2",
"forky-linux-amd64": "0.6.2",
"forky-windows-arm64": "0.6.2",
"forky-windows-amd64": "0.6.2"
}
}
28 changes: 28 additions & 0 deletions npm/forky/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env node

import { spawnSync } from "child_process"

function getExePath() {
const arch = process.arch;
let os = process.platform as string;
let extension = '';
if (['win32', 'cygwin'].includes(process.platform)) {
os = 'windows';
extension = '.exe';
}

try {
// Since the bin will be located inside `node_modules`, we can simply call require.resolve
return require.resolve(`forky-${os}-${arch}/bin/forky${extension}`)
} catch (e) {
throw new Error(`Couldn't find forky binary inside node_modules for ${os}-${arch}`)
}
}

function runForky() {
const args = process.argv.slice(2)
const processResult = spawnSync(getExePath(), args, { stdio: "inherit" })
process.exit(processResult.status ?? 0)
}

runForky()
Empty file added npm/forky/tsconfig.json
Empty file.
18 changes: 18 additions & 0 deletions npm/package.json.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "${node_pkg}",
"version": "${version}",
"description": "Synchronize your forks with ease",
"repository": {
"type": "git",
"url": "git+https://github.com/thetnaingtn/forky.git"
},
"keywords": ["github","go", "cli", "synchronize", "sync", "bubble", "bubbletea","github-api", "fork"],
"license": "MIT OR Apache-2.0",
"homepage": "https://github.com/thetnaingtn/forky#readme",
"os": [
"${node_os}"
],
"cpu": [
"${node_arch}"
]
}
35 changes: 0 additions & 35 deletions package-lock.json

This file was deleted.

32 changes: 0 additions & 32 deletions package.json

This file was deleted.

Loading

0 comments on commit ea0fb52

Please sign in to comment.