Skip to content

Commit

Permalink
Always opt for linux musl binary, automate release process (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgb-io authored Jul 19, 2023
1 parent 94a3911 commit 06e96cf
Show file tree
Hide file tree
Showing 18 changed files with 705 additions and 356 deletions.
16 changes: 4 additions & 12 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,13 @@ jobs = 8
rustdocflags = ["--cfg", "docsrs"]
rustflags = []

[target.x86_64-unknown-linux-gnu]
rustflags = ["-C", "target-feature=+sse2"]

[target.aarch64-apple-darwin]
rustflags = []

[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
rustflags = []

[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-musl-gcc"
rustflags = ["-C", "target-feature=-crt-static", "-C", "link-arg=-lgcc"]

[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
rustflags = []

[target.aarch64-linux-android]
rustflags = []

Expand All @@ -33,4 +22,7 @@ linker = "rust-lld"
rustflags = []

[target.wasm32-unknown-unknown]
rustflags = []
rustflags = []

[target.arm-unknown-linux-musleabi]
linker = "arm-linux-gnueabi-gcc"
23 changes: 23 additions & 0 deletions .github/foo.ts
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;
};
24 changes: 24 additions & 0 deletions .github/verdaccio-config.yml
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}
49 changes: 0 additions & 49 deletions .github/workflows/CI.yml

This file was deleted.

153 changes: 153 additions & 0 deletions .github/workflows/build.yml
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
98 changes: 98 additions & 0 deletions .github/workflows/publish-dry-run.yml
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
Loading

0 comments on commit 06e96cf

Please sign in to comment.