Skip to content

Commit eb37234

Browse files
committed
Merge branch 'feature/cicd' into development
2 parents 12f4f27 + 8ce70f0 commit eb37234

11 files changed

Lines changed: 971 additions & 83 deletions

File tree

.agents/skills/ci-cd/SKILL.md

Lines changed: 480 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 80 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
name: Crates.io Release
22

33
on:
4+
push:
5+
tags:
6+
- "v*.*.*"
47
workflow_dispatch:
8+
inputs:
9+
tag:
10+
description: "Release tag (e.g. v0.3.35)"
11+
required: true
12+
13+
permissions:
14+
contents: read
515

616
env:
717
CARGO_TERM_COLOR: always
@@ -15,23 +25,86 @@ env:
1525
GH_OAUTH_REDIRECT_PORT: ${{ secrets.GH_OAUTH_REDIRECT_PORT }}
1626

1727
jobs:
18-
build:
28+
publish:
29+
name: Publish to crates.io
1930
runs-on: ubuntu-latest
2031

2132
steps:
2233
- name: Checkout
23-
uses: actions/checkout@v3
34+
uses: actions/checkout@v6
35+
with:
36+
ref: ${{ github.event.inputs.tag || github.ref }}
37+
38+
- name: Set the release version
39+
shell: bash
40+
run: |
41+
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
42+
release_version="${GITHUB_REF_NAME#v}"
43+
else
44+
release_version="${{ github.event.inputs.tag }}"
45+
release_version="${release_version#v}"
46+
fi
47+
48+
echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"
49+
50+
- name: Read Rust toolchain
51+
shell: bash
52+
run: |
53+
rust_toolchain="$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml | head -n 1)"
54+
if [ -z "$rust_toolchain" ]; then
55+
echo "Failed to read Rust toolchain from rust-toolchain.toml" >&2
56+
exit 1
57+
fi
58+
59+
echo "RUST_TOOLCHAIN=${rust_toolchain}" >> "$GITHUB_ENV"
60+
61+
- name: Install toolkit
62+
uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9
63+
with:
64+
toolchain: ${{ env.RUST_TOOLCHAIN }}
2465

25-
- name: Setup Rust toolchain
26-
uses: dtolnay/rust-toolchain@stable
66+
- name: Setup Rust cache
67+
uses: Swatinem/rust-cache@v2
68+
with:
69+
key: publish
2770

2871
- name: Create .env file
2972
run: |
3073
touch .env
3174
echo CLI_CLIENT_SECRET=${{ secrets.CLI_CLIENT_SECRET }} >> .env
3275
cat .env
3376
77+
- name: Verify Cargo.toml version matches tag
78+
shell: bash
79+
run: |
80+
CARGO_VERSION=$(cargo metadata --no-deps --format-version 1 \
81+
| jq -r '.packages[] | select(.name == "smbcloud-cli") | .version')
82+
83+
echo "Cargo.toml version : ${CARGO_VERSION}"
84+
echo "Release tag version: ${RELEASE_VERSION}"
85+
86+
if [[ "${CARGO_VERSION}" != "${RELEASE_VERSION}" ]]; then
87+
echo "::error::Version mismatch — bump version in Cargo.toml before releasing."
88+
exit 1
89+
fi
90+
91+
- name: Check whether release already exists on crates.io
92+
id: crates-check
93+
shell: bash
94+
run: |
95+
if curl -fsS \
96+
-H "User-Agent: smbcloud-cli-release-workflow" \
97+
"https://crates.io/api/v1/crates/smbcloud-cli/${RELEASE_VERSION}" \
98+
>/dev/null 2>&1; then
99+
echo "smbcloud-cli ${RELEASE_VERSION} already exists on crates.io, skipping publish"
100+
echo "exists=true" >> "$GITHUB_OUTPUT"
101+
else
102+
echo "exists=false" >> "$GITHUB_OUTPUT"
103+
fi
104+
34105
- name: Publish to crates.io
35-
uses: katyo/publish-crates@v2
36-
with:
37-
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
106+
if: steps.crates-check.outputs.exists != 'true'
107+
shell: bash
108+
env:
109+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
110+
run: cargo publish --locked --package smbcloud-cli

.github/workflows/release-github.yml

Lines changed: 88 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,83 +5,142 @@ on:
55
tags:
66
- "v*.*.*"
77
workflow_dispatch:
8-
9-
env:
10-
# The smbcloud-cli binary name
11-
PROJECT_NAME: smb
8+
inputs:
9+
tag:
10+
description: "Release tag (e.g. v0.3.35)"
11+
required: true
1212

1313
permissions:
1414
contents: write
1515

16+
env:
17+
PROJECT_NAME: smb
18+
CARGO_TERM_COLOR: always
19+
1620
jobs:
1721
build:
22+
name: Build binary (${{ matrix.name }})
1823
runs-on: ${{ matrix.runner }}
1924

2025
strategy:
26+
fail-fast: false
2127
matrix:
2228
include:
2329
- name: linux-amd64
2430
runner: ubuntu-latest
2531
target: x86_64-unknown-linux-gnu
32+
- name: linux-arm64
33+
runner: ubuntu-24.04-arm
34+
target: aarch64-unknown-linux-gnu
2635
- name: win-amd64
2736
runner: windows-latest
2837
target: x86_64-pc-windows-msvc
29-
#- name: macos-amd64
30-
# runner: macos-latest
31-
# target: x86_64-apple-darwin
38+
- name: win-arm64
39+
runner: windows-latest
40+
target: aarch64-pc-windows-msvc
41+
- name: macos-amd64
42+
runner: macos-15-intel
43+
target: x86_64-apple-darwin
3244
- name: macos-arm64
3345
runner: macos-latest
3446
target: aarch64-apple-darwin
3547

3648
steps:
3749
- name: Checkout
38-
uses: actions/checkout@v3
39-
40-
- name: Install Rust
41-
uses: dtolnay/rust-toolchain@stable
50+
uses: actions/checkout@v6
4251
with:
43-
toolchain: 1.92
44-
targets: "${{ matrix.target }}"
52+
ref: ${{ github.event.inputs.tag || github.ref }}
4553

46-
#- name: Install OpenSSL
47-
# if: matrix.name == 'macos-amd64'
48-
# run: brew install openssl@3
54+
- name: Set the release version
55+
shell: bash
56+
run: |
57+
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
58+
release_version="${GITHUB_REF_NAME#v}"
59+
else
60+
release_version="${{ github.event.inputs.tag }}"
61+
release_version="${release_version#v}"
62+
fi
63+
64+
echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"
65+
66+
- name: Read Rust toolchain
67+
shell: bash
68+
run: |
69+
rust_toolchain="$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml | head -n 1)"
70+
if [ -z "$rust_toolchain" ]; then
71+
echo "Failed to read Rust toolchain from rust-toolchain.toml" >&2
72+
exit 1
73+
fi
4974
50-
- name: Setup Cache
75+
echo "RUST_TOOLCHAIN=${rust_toolchain}" >> "$GITHUB_ENV"
76+
77+
- name: Install toolkit
78+
uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9
79+
with:
80+
toolchain: ${{ env.RUST_TOOLCHAIN }}
81+
targets: ${{ matrix.target }}
82+
83+
- name: Setup Rust cache
5184
uses: Swatinem/rust-cache@v2
85+
with:
86+
key: github-${{ matrix.target }}
5287

5388
- name: Create .env file
5489
run: |
5590
touch .env
5691
echo CLI_CLIENT_SECRET=${{ secrets.CLI_CLIENT_SECRET }} >> .env
5792
cat .env
5893
59-
- name: Build Binary
60-
run: cargo build --verbose --locked --release --target ${{ matrix.target }}
94+
- name: Build binary
95+
shell: bash
96+
run: cargo build --locked --release --target ${{ matrix.target }} --package smbcloud-cli
6197

62-
- name: Release Binary
98+
- name: Package binary
6399
shell: bash
64100
run: |
65101
BIN_SUFFIX=""
66102
if [[ "${{ matrix.runner }}" == "windows-latest" ]]; then
67103
BIN_SUFFIX=".exe"
68104
fi
69105
70-
# The built binary output location
71106
BIN_OUTPUT="target/${{ matrix.target }}/release/${PROJECT_NAME}${BIN_SUFFIX}"
72-
73-
# Define a better name for the final binary
74107
BIN_RELEASE="${PROJECT_NAME}-${{ matrix.name }}${BIN_SUFFIX}"
75-
BIN_RELEASE_VERSIONED="${PROJECT_NAME}-${{ github.ref_name }}-${{ matrix.name }}${BIN_SUFFIX}"
76108
77-
# Move the built binary where you want it
78-
DEST_DIR="./release"
109+
mkdir -p ./release
110+
mv "${BIN_OUTPUT}" "./release/${BIN_RELEASE}"
111+
112+
- name: Upload artifact
113+
uses: actions/upload-artifact@v7
114+
with:
115+
name: binary-${{ matrix.name }}
116+
path: release/*
79117

80-
mkdir -p "${DEST_DIR}"
81-
mv "${BIN_OUTPUT}" "${DEST_DIR}/${BIN_RELEASE}"
118+
release:
119+
name: Create GitHub Release
120+
needs: build
121+
runs-on: ubuntu-latest
122+
if: github.ref_type == 'tag' || github.event_name == 'workflow_dispatch'
123+
124+
steps:
125+
- name: Resolve tag
126+
id: tag
127+
shell: bash
128+
run: |
129+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
130+
echo "tag=${{ github.event.inputs.tag }}" >> "$GITHUB_OUTPUT"
131+
else
132+
echo "tag=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
133+
fi
134+
135+
- name: Download all artifacts
136+
uses: actions/download-artifact@v7
137+
with:
138+
pattern: "binary-*"
139+
path: release
140+
merge-multiple: true
82141

83142
- name: Release
84143
uses: softprops/action-gh-release@v2
85-
if: github.ref_type == 'tag'
86144
with:
145+
tag_name: ${{ steps.tag.outputs.tag }}
87146
files: release/*

.github/workflows/release-npm.yml

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on:
55
tags:
66
- "v*.*.*"
77
workflow_dispatch:
8+
inputs:
9+
tag:
10+
description: "Release tag (e.g. v0.3.35)"
11+
required: true
812

913
permissions:
1014
id-token: write
@@ -33,13 +37,11 @@ jobs:
3337
OS: ubuntu-latest,
3438
TARGET: x86_64-unknown-linux-gnu,
3539
}
36-
# Cannot cross-compile for now
37-
#- {
38-
# NAME: linux-arm64-glibc,
39-
# OS: ubuntu-latest,
40-
# TOOLCHAIN: stable,
41-
# TARGET: aarch64-unknown-linux-gnu,
42-
# }
40+
- {
41+
NAME: linux-arm64-glibc,
42+
OS: ubuntu-24.04-arm,
43+
TARGET: aarch64-unknown-linux-gnu,
44+
}
4345
- {
4446
NAME: win32-x64-msvc,
4547
OS: windows-2022,
@@ -63,14 +65,17 @@ jobs:
6365
steps:
6466
- name: Checkout
6567
uses: actions/checkout@v6
68+
with:
69+
ref: ${{ github.event.inputs.tag || github.ref }}
6670

6771
- name: Set the release version
6872
shell: bash
6973
run: |
7074
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
7175
release_version="${GITHUB_REF_NAME#v}"
7276
else
73-
release_version="$(sed -n 's/^version = "\(.*\)"/\1/p' crates/cli/Cargo.toml | head -n 1)"
77+
release_version="${{ github.event.inputs.tag }}"
78+
release_version="${release_version#v}"
7479
fi
7580
7681
echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"
@@ -110,7 +115,7 @@ jobs:
110115
GH_OAUTH_REDIRECT_URI: ${{ secrets.GH_OAUTH_REDIRECT_URI }}
111116
shell: bash
112117
run: |
113-
cargo build --release --locked --target ${{ matrix.build.TARGET }}
118+
cargo build --release --locked --target ${{ matrix.build.TARGET }} --package smbcloud-cli
114119
115120
- name: Install node
116121
uses: actions/setup-node@v6
@@ -119,6 +124,8 @@ jobs:
119124
registry-url: "https://registry.npmjs.org"
120125

121126
- name: Publish to NPM
127+
env:
128+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
122129
shell: bash
123130
run: |
124131
# We want to name our npm package @smbcloud/cli, but the main command is smb.
@@ -171,14 +178,17 @@ jobs:
171178
steps:
172179
- name: Checkout
173180
uses: actions/checkout@v6
181+
with:
182+
ref: ${{ github.event.inputs.tag || github.ref }}
174183

175184
- name: Set the release version
176185
shell: bash
177186
run: |
178187
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
179188
release_version="${GITHUB_REF_NAME#v}"
180189
else
181-
release_version="$(sed -n 's/^version = "\(.*\)"/\1/p' crates/cli/Cargo.toml | head -n 1)"
190+
release_version="${{ github.event.inputs.tag }}"
191+
release_version="${release_version#v}"
182192
fi
183193
184194
echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"
@@ -190,6 +200,8 @@ jobs:
190200
registry-url: "https://registry.npmjs.org"
191201

192202
- name: Publish the package
203+
env:
204+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
193205
shell: bash
194206
run: |
195207
cd npm/smbcloud-cli

0 commit comments

Comments
 (0)