-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Always opt for linux musl binary, automate release process (#43)
- Loading branch information
Showing
18 changed files
with
705 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export type SimpleGraph<T> = Map<T, T[]>; | ||
|
||
export const breadthFirstSearch = <T>(graph: SimpleGraph<T>, start: T): T[] => { | ||
let bfsOrder: T[] = []; | ||
|
||
const bfs = (queue: T[], visited: Set<T>) => { | ||
if (queue.length === 0) return; | ||
|
||
const [node, ...rest] = queue; | ||
bfsOrder = [...bfsOrder, node]; | ||
|
||
const unvisitedNeighbors = | ||
graph.get(node)?.filter((neighbor) => !visited.has(neighbor)) || []; | ||
const newQueue = [...rest, ...unvisitedNeighbors]; | ||
const newVisited = new Set([...visited, ...unvisitedNeighbors]); | ||
|
||
bfs(newQueue, newVisited); | ||
}; | ||
|
||
bfs([start], new Set([start])); | ||
|
||
return bfsOrder; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
auth: | ||
auth-memory: | ||
users: | ||
foo: | ||
name: test | ||
password: test | ||
store: | ||
memory: | ||
limit: 1000 | ||
## we don't need any remote request | ||
uplinks: | ||
packages: | ||
'@*/*': | ||
access: $all | ||
publish: $all | ||
'**': | ||
access: $all | ||
publish: $all | ||
middlewares: | ||
audit: | ||
enabled: true | ||
max_body_size: 100mb | ||
log: | ||
- {type: stdout, format: pretty, level: trace} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
name: Build Binaries & Upload Artifacts | ||
|
||
on: workflow_call | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
CARGO_INCREMENTAL: 0 | ||
|
||
jobs: | ||
upload_assets_macos: | ||
runs-on: macos-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Setup Rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: stable | ||
components: rustfmt, clippy | ||
target: x86_64-apple-darwin | ||
default: true | ||
|
||
- name: Install dependencies | ||
run: brew install llvm | ||
|
||
- name: Build x86_64-apple-darwin | ||
run: cargo build --release --target=x86_64-apple-darwin | ||
|
||
- name: Setup Rust for aarch64-apple-darwin | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: stable | ||
target: aarch64-apple-darwin | ||
default: true | ||
|
||
- name: Build aarch64-apple-darwin | ||
run: cargo build --release --target=aarch64-apple-darwin | ||
|
||
- name: Set permissions for macOS binaries | ||
run: | | ||
chmod +x target/x86_64-apple-darwin/release/fta | ||
chmod +x target/aarch64-apple-darwin/release/fta | ||
- name: Create tarballs and move binaries | ||
run: | | ||
tar czvf x86_64-apple-darwin.tar.gz -C target/x86_64-apple-darwin/release fta | ||
tar czvf aarch64-apple-darwin.tar.gz -C target/aarch64-apple-darwin/release fta | ||
- name: Upload binaries as artifacts | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: macos-binaries | ||
path: | | ||
*.tar.gz | ||
upload_assets_windows: | ||
runs-on: windows-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Setup Rust for x86_64-pc-windows-msvc | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: stable | ||
components: rustfmt, clippy | ||
target: x86_64-pc-windows-msvc | ||
default: true | ||
override: true | ||
|
||
- name: Build x86_64-pc-windows-msvc | ||
run: cargo build --release --target=x86_64-pc-windows-msvc | ||
|
||
- name: Setup Rust for aarch64-pc-windows-msvc | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: stable | ||
target: aarch64-pc-windows-msvc | ||
default: true | ||
override: true | ||
|
||
- name: Build aarch64-pc-windows-msvc | ||
run: cargo build --release --target=aarch64-pc-windows-msvc | ||
|
||
- name: Create zipfiles and move binaries | ||
shell: pwsh | ||
run: | | ||
Compress-Archive -Path target/x86_64-pc-windows-msvc/release/fta.exe -DestinationPath x86_64-pc-windows-msvc.zip | ||
Compress-Archive -Path target/aarch64-pc-windows-msvc/release/fta.exe -DestinationPath aarch64-pc-windows-msvc.zip | ||
- name: Upload binaries as artifacts | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: windows-binaries | ||
path: | | ||
*.zip | ||
upload_assets_linux: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Update packages | ||
run: sudo apt-get update | ||
|
||
- name: Install aarch64 dependencies | ||
run: sudo apt-get install -y gcc-aarch64-linux-gnu libc6-dev-arm64-cross | ||
|
||
- name: Install aarch64-unknown-linux-musl dependencies | ||
run: | | ||
sudo apt-get install -y musl-tools | ||
sudo apt-get install gcc-arm-linux-gnueabi | ||
- name: Install Rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: stable | ||
components: rustfmt, clippy | ||
profile: minimal | ||
target: x86_64-unknown-linux-musl | ||
|
||
- name: Add Rust targets | ||
run: | | ||
rustup target add x86_64-unknown-linux-musl | ||
rustup target add aarch64-unknown-linux-musl | ||
rustup target add arm-unknown-linux-musleabi | ||
- name: Install MUSL toolchain for AArch64 | ||
run: | | ||
wget -q https://musl.cc/aarch64-linux-musl-cross.tgz | ||
tar -xf aarch64-linux-musl-cross.tgz | ||
echo "$(pwd)/aarch64-linux-musl-cross/bin" >> $GITHUB_PATH | ||
- name: Build and tarball | ||
run: | | ||
TARGETS=( | ||
x86_64-unknown-linux-musl | ||
aarch64-unknown-linux-musl | ||
arm-unknown-linux-musleabi | ||
) | ||
for TARGET in "${TARGETS[@]}"; do | ||
echo "Building for $TARGET" | ||
cargo build --release --target="$TARGET" | ||
chmod +x target/${TARGET}/release/fta | ||
tar czf "${TARGET}.tar.gz" -C "./target/${TARGET}/release/" fta | ||
done | ||
- name: Upload binaries as artifacts | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: linux-binaries | ||
path: | | ||
*.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
name: Publish NPM Package (Dry Run) | ||
|
||
on: workflow_call | ||
|
||
jobs: | ||
publish_fta_cli_dry_run: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node.js environment | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
|
||
- name: Download macOS artifacts | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: macos-binaries | ||
path: artifact/ | ||
|
||
- name: Download linux artifacts | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: linux-binaries | ||
path: artifact/ | ||
|
||
- name: Download windows artifacts | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: windows-binaries | ||
path: artifact/ | ||
|
||
- name: Extract nix artifacts | ||
run: | | ||
for file in artifact/*.tar.gz; do | ||
base=$(basename -- "$file") | ||
dirname="${base%%.*}" | ||
mkdir -p packages/fta/binaries/"$dirname" | ||
tar -xzf "$file" -C packages/fta/binaries/"$dirname" | ||
done | ||
- name: Extract artifacts | ||
run: | | ||
for file in artifact/*.zip; do | ||
dir=$(basename "$file" .zip) | ||
mkdir -p "packages/fta/binaries/$dir" | ||
unzip -o "$file" -d "packages/fta/binaries/$dir" | ||
done | ||
# List out the binaries dir | ||
ls -R packages/fta/binaries/ | ||
- name: Install Verdaccio | ||
run: npm install -g verdaccio verdaccio-memory verdaccio-auth-memory | ||
|
||
- name: Setup Verdaccio Config | ||
run: | | ||
mkdir -p $HOME/.config/verdaccio | ||
cp .github/verdaccio-config.yml $HOME/.config/verdaccio/config.yml | ||
- name: Start Verdaccio | ||
run: | | ||
npx verdaccio --config $HOME/.config/verdaccio/config.yml --listen 4873 & | ||
sleep 10 | ||
- name: Publish package | ||
run: | | ||
npm config set registry http://localhost:4873/ | ||
npm config set //localhost:4873/:_authToken "$(echo -n 'test:test' | base64)" | ||
cd packages/fta | ||
npm publish --registry http://localhost:4873 | ||
cd ../ | ||
- name: Install and check package | ||
run: | | ||
# Install FTA via the CLI package | ||
npm install fta-cli --registry http://localhost:4873 | ||
# Verify the output is what we expect | ||
sudo apt-get install -y jq | ||
EXPECTED_OUTPUT=$(cat <<'EOF' | ||
[{"file_name":"foo.ts","cyclo":3,"halstead":{"uniq_operators":13,"uniq_operands":21,"total_operators":39,"total_operands":44,"program_length":34,"vocabulary_size":83,"volume":216.75134066579542,"difficulty":9.068181818181818,"effort":1965.5405664920995,"time":109.19669813844997,"bugs":0.07225044688859847},"line_count":23,"fta_score":42.65462143345264,"assessment":"OK"}] | ||
EOF | ||
) | ||
OUTPUT=$(npx fta-cli .github --json) | ||
if [ "$(echo "$OUTPUT" | jq --sort-keys '.')" == "$(echo "$EXPECTED_OUTPUT" | jq --sort-keys '.')" ]; then | ||
echo "$OUTPUT" | ||
echo "Output matches expected" | ||
else | ||
echo "Output does not match expected." | ||
echo "Expected:" | ||
echo "$EXPECTED_OUTPUT" | ||
echo "Got:" | ||
echo "$OUTPUT" | ||
exit 1 | ||
fi |
Oops, something went wrong.