Skip to content

Commit

Permalink
👷 Move into one workflow and simplify postinstall flow
Browse files Browse the repository at this point in the history
  • Loading branch information
segersniels committed Sep 17, 2023
1 parent 2e5bb7f commit edebb95
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 186 deletions.
42 changes: 41 additions & 1 deletion .github/workflows/build.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
- master
pull_request:


concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
Expand Down Expand Up @@ -65,6 +64,7 @@ jobs:

release:
needs: build
environment: production
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
Expand All @@ -85,3 +85,43 @@ jobs:
./bin/supdock-macos
./bin/supdock-aarch64-linux
./bin/supdock-amd64-linux
cargo:
needs: release
environment: production
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v2
- name: Publish to Cargo
uses: actions-rs/cargo@v1
with:
command: publish
args: --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

npm:
needs: cargo
environment: production
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: "18.x"
registry-url: "https://registry.npmjs.org"
- uses: actions/download-artifact@v3
with:
name: bin
path: bin
- name: Get current package version
id: current_version
run: echo "version=$(make version)" >> $GITHUB_OUTPUT
- name: Publish to NPM
run: |
npm version ${{ steps.current_version.outputs.version }} --no-git-tag-version --no-commit-hooks --allow-same-version
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
35 changes: 0 additions & 35 deletions .github/workflows/publish.yml

This file was deleted.

54 changes: 0 additions & 54 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 20 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@
"name": "supdock",
"version": "3.0.0",
"description": "What's Up, Doc(ker)? A slightly more visual way to interact with the docker daemon",
"files": [
"bin"
],
"bin": {
"supdock": "./bin/supdock"
},
"scripts": {
"postinstall": "./scripts/postinstall.sh",
"generate:changelog": "./scripts/generate-tags.sh && gitmoji-changelog"
},
"devDependencies": {
"gitmoji-changelog": "^2.3.0"
},
"author": "Niels Segers",
"license": "ISC",
"homepage": "https://github.com/segersniels/supdock#readme",
"bugs": {
"url": "https://github.com/segersniels/supdock/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/segersniels/supdock.git"
Expand All @@ -15,25 +34,5 @@
"cli",
"compose",
"docker-compose"
],
"author": "Niels Segers",
"license": "ISC",
"bugs": {
"url": "https://github.com/segersniels/supdock/issues"
},
"homepage": "https://github.com/segersniels/supdock#readme",
"bin": {
"supdock": "./bin/supdock"
},
"scripts": {
"preinstall": "node ./scripts/preinstall.js",
"preuninstall": "node ./scripts/preuninstall.js",
"generate:changelog": "./scripts/generate-tags.sh && gitmoji-changelog"
},
"dependencies": {
"undici": "^5.21.2"
},
"devDependencies": {
"gitmoji-changelog": "^2.3.0"
}
]
}
68 changes: 68 additions & 0 deletions scripts/postinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

BIN_DIR="./bin"
BINARY="supdock"
PLATFORM=$(uname)

function check_if_binary_exists() {
binary_path="$BIN_DIR/$1"

if [ ! -f "$binary_path" ]; then
echo "File ${binary_path} not found, skipping..."
exit 0
fi
}

function determine_platform() {
case $PLATFORM in
Linux)
if [[ $(uname -m) == "aarch64" ]]; then
platform_binary="supdock-aarch64-linux"
else
platform_binary="supdock-amd64-linux"
fi
;;
Darwin)
platform_binary="supdock-macos"
;;
*)
echo "Unsupported platform: $PLATFORM"
exit 0
;;
esac

check_if_binary_exists $platform_binary

return $platform_binary
}

function remove_other_binaries() {
for file in "$BIN_DIR"/*; do
if [ ! -f "$file" ]; then
continue
fi

filename=$(basename "$file")

if [[ ! "$filename" =~ ^$1 ]]; then
echo "Removing file: $file"
rm "$file"
fi
done
}

function rename_binary() {
binary_path="$BIN_DIR/$1"

mv $binary_path $BIN_DIR/$BINARY
}

function main() {
determine_platform
platform_binary=$?

remove_other_binaries $platform_binary
rename_binary $platform_binary
}

main
65 changes: 0 additions & 65 deletions scripts/preinstall.js

This file was deleted.

10 changes: 0 additions & 10 deletions scripts/preuninstall.js

This file was deleted.

0 comments on commit edebb95

Please sign in to comment.