|
1 | 1 | name: Release |
2 | 2 |
|
3 | 3 | on: |
4 | | - push: |
5 | | - tags: |
6 | | - - 'v*' |
7 | | - workflow_dispatch: |
8 | | - inputs: |
9 | | - version: |
10 | | - description: 'Version to release (e.g., 2.0.1)' |
11 | | - required: true |
12 | | - type: string |
13 | | - dry_run: |
14 | | - description: 'Dry run (skip npm publish)' |
15 | | - required: false |
16 | | - type: boolean |
17 | | - default: false |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + version: |
| 10 | + description: "Version to release (e.g., 2.0.1)" |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + dry_run: |
| 14 | + description: "Dry run (skip npm publish)" |
| 15 | + required: false |
| 16 | + type: boolean |
| 17 | + default: false |
18 | 18 |
|
19 | 19 | permissions: |
20 | | - contents: write |
21 | | - id-token: write # Required for npm provenance/trusted publishing |
| 20 | + contents: write |
| 21 | + id-token: write # Required for npm provenance/trusted publishing |
22 | 22 |
|
23 | 23 | jobs: |
24 | | - build: |
25 | | - strategy: |
26 | | - matrix: |
27 | | - include: |
28 | | - - os: ubuntu-latest |
29 | | - target: x86_64-unknown-linux-gnu |
30 | | - npm-dir: linux-x64 |
31 | | - binary: zenv |
32 | | - - os: ubuntu-latest |
33 | | - target: aarch64-unknown-linux-gnu |
34 | | - npm-dir: linux-arm64 |
35 | | - binary: zenv |
36 | | - - os: macos-latest |
37 | | - target: x86_64-apple-darwin |
38 | | - npm-dir: darwin-x64 |
39 | | - binary: zenv |
40 | | - - os: macos-latest |
41 | | - target: aarch64-apple-darwin |
42 | | - npm-dir: darwin-arm64 |
43 | | - binary: zenv |
44 | | - - os: windows-latest |
45 | | - target: x86_64-pc-windows-msvc |
46 | | - npm-dir: win32-x64 |
47 | | - binary: zenv.exe |
48 | | - |
49 | | - runs-on: ${{ matrix.os }} |
50 | | - steps: |
51 | | - - uses: actions/checkout@v4 |
52 | | - |
53 | | - - name: Install Rust |
54 | | - uses: dtolnay/rust-toolchain@stable |
55 | | - with: |
56 | | - targets: ${{ matrix.target }} |
57 | | - |
58 | | - - name: Install cross (Linux ARM64) |
59 | | - if: matrix.target == 'aarch64-unknown-linux-gnu' |
60 | | - run: cargo install cross |
61 | | - |
62 | | - - name: Build (native) |
63 | | - if: matrix.target != 'aarch64-unknown-linux-gnu' |
64 | | - run: cargo build --release --target ${{ matrix.target }} |
65 | | - |
66 | | - - name: Build (cross) |
67 | | - if: matrix.target == 'aarch64-unknown-linux-gnu' |
68 | | - run: cross build --release --target ${{ matrix.target }} |
69 | | - |
70 | | - - name: Prepare npm package |
71 | | - shell: bash |
72 | | - run: | |
73 | | - mkdir -p npm/${{ matrix.npm-dir }}/bin |
74 | | - cp target/${{ matrix.target }}/release/${{ matrix.binary }} npm/${{ matrix.npm-dir }}/bin/ |
75 | | -
|
76 | | - - name: Upload artifact |
77 | | - uses: actions/upload-artifact@v4 |
78 | | - with: |
79 | | - name: ${{ matrix.npm-dir }} |
80 | | - path: npm/${{ matrix.npm-dir }} |
81 | | - |
82 | | - publish: |
83 | | - needs: build |
84 | | - runs-on: ubuntu-latest |
85 | | - environment: npm-publish # Optional: use GitHub environment for extra protection |
86 | | - permissions: |
87 | | - contents: write |
88 | | - id-token: write # Required for npm provenance |
89 | | - steps: |
90 | | - - uses: actions/checkout@v4 |
91 | | - |
92 | | - - name: Setup Node.js |
93 | | - uses: actions/setup-node@v4 |
94 | | - with: |
95 | | - node-version: '20' |
96 | | - registry-url: 'https://registry.npmjs.org' |
97 | | - |
98 | | - - name: Download all artifacts |
99 | | - uses: actions/download-artifact@v4 |
100 | | - with: |
101 | | - path: npm-artifacts |
102 | | - |
103 | | - - name: Prepare packages |
104 | | - run: | |
105 | | - # Copy built binaries to npm package directories |
106 | | - for dir in npm-artifacts/*/; do |
107 | | - name=$(basename "$dir") |
108 | | - cp -r "$dir"/* "npm/$name/" |
109 | | - done |
110 | | -
|
111 | | - # Copy main binary to zenv package for fallback |
112 | | - mkdir -p npm/zenv/bin |
113 | | - cp npm/linux-x64/bin/zenv npm/zenv/bin/ || true |
114 | | -
|
115 | | - - name: Update versions (manual dispatch) |
116 | | - if: ${{ inputs.version }} |
117 | | - run: | |
118 | | - VERSION="${{ inputs.version }}" |
119 | | - for pkg in npm/*/package.json; do |
120 | | - sed -i "s/\"version\": \"[^\"]*\"/\"version\": \"$VERSION\"/" "$pkg" |
121 | | - # Also update optionalDependencies versions in main package |
122 | | - if [[ "$pkg" == "npm/zenv/package.json" ]]; then |
123 | | - sed -i "s/@modlogtv\/zenv-\([^\"]*\)\": \"[^\"]*\"/@modlogtv\/zenv-\1\": \"$VERSION\"/g" "$pkg" |
124 | | - fi |
125 | | - done |
126 | | - echo "Updated all packages to version $VERSION" |
127 | | -
|
128 | | - - name: Publish @modlogtv/zenv-linux-x64 |
129 | | - if: ${{ !inputs.dry_run }} |
130 | | - working-directory: npm/linux-x64 |
131 | | - run: npm publish --access public --provenance |
132 | | - |
133 | | - - name: Publish @modlogtv/zenv-linux-arm64 |
134 | | - if: ${{ !inputs.dry_run }} |
135 | | - working-directory: npm/linux-arm64 |
136 | | - run: npm publish --access public --provenance |
137 | | - |
138 | | - - name: Publish @modlogtv/zenv-darwin-x64 |
139 | | - if: ${{ !inputs.dry_run }} |
140 | | - working-directory: npm/darwin-x64 |
141 | | - run: npm publish --access public --provenance |
142 | | - |
143 | | - - name: Publish @modlogtv/zenv-darwin-arm64 |
144 | | - if: ${{ !inputs.dry_run }} |
145 | | - working-directory: npm/darwin-arm64 |
146 | | - run: npm publish --access public --provenance |
147 | | - |
148 | | - - name: Publish @modlogtv/zenv-win32-x64 |
149 | | - if: ${{ !inputs.dry_run }} |
150 | | - working-directory: npm/win32-x64 |
151 | | - run: npm publish --access public --provenance |
152 | | - |
153 | | - - name: Publish @modlogtv/zenv |
154 | | - if: ${{ !inputs.dry_run }} |
155 | | - working-directory: npm/zenv |
156 | | - run: npm publish --access public --provenance |
157 | | - |
158 | | - - name: Create GitHub Release |
159 | | - if: ${{ !inputs.dry_run }} |
160 | | - uses: softprops/action-gh-release@v1 |
161 | | - with: |
162 | | - tag_name: ${{ inputs.version && format('v{0}', inputs.version) || github.ref_name }} |
163 | | - files: | |
164 | | - npm-artifacts/*/bin/* |
165 | | - generate_release_notes: true |
| 24 | + build: |
| 25 | + strategy: |
| 26 | + matrix: |
| 27 | + include: |
| 28 | + - os: ubuntu-latest |
| 29 | + target: x86_64-unknown-linux-gnu |
| 30 | + npm-dir: linux-x64 |
| 31 | + binary: zenv |
| 32 | + - os: ubuntu-latest |
| 33 | + target: aarch64-unknown-linux-gnu |
| 34 | + npm-dir: linux-arm64 |
| 35 | + binary: zenv |
| 36 | + - os: macos-latest |
| 37 | + target: x86_64-apple-darwin |
| 38 | + npm-dir: darwin-x64 |
| 39 | + binary: zenv |
| 40 | + - os: macos-latest |
| 41 | + target: aarch64-apple-darwin |
| 42 | + npm-dir: darwin-arm64 |
| 43 | + binary: zenv |
| 44 | + - os: windows-latest |
| 45 | + target: x86_64-pc-windows-msvc |
| 46 | + npm-dir: win32-x64 |
| 47 | + binary: zenv.exe |
| 48 | + |
| 49 | + runs-on: ${{ matrix.os }} |
| 50 | + steps: |
| 51 | + - uses: actions/checkout@v4 |
| 52 | + |
| 53 | + - name: Install Rust |
| 54 | + uses: dtolnay/rust-toolchain@stable |
| 55 | + with: |
| 56 | + targets: ${{ matrix.target }} |
| 57 | + |
| 58 | + - name: Install cross (Linux ARM64) |
| 59 | + if: matrix.target == 'aarch64-unknown-linux-gnu' |
| 60 | + run: cargo install cross |
| 61 | + |
| 62 | + - name: Build (native) |
| 63 | + if: matrix.target != 'aarch64-unknown-linux-gnu' |
| 64 | + run: cargo build --release --target ${{ matrix.target }} |
| 65 | + |
| 66 | + - name: Build (cross) |
| 67 | + if: matrix.target == 'aarch64-unknown-linux-gnu' |
| 68 | + run: cross build --release --target ${{ matrix.target }} |
| 69 | + |
| 70 | + - name: Prepare npm package |
| 71 | + shell: bash |
| 72 | + run: | |
| 73 | + mkdir -p npm/${{ matrix.npm-dir }}/bin |
| 74 | + cp target/${{ matrix.target }}/release/${{ matrix.binary }} npm/${{ matrix.npm-dir }}/bin/ |
| 75 | +
|
| 76 | + - name: Upload artifact |
| 77 | + uses: actions/upload-artifact@v4 |
| 78 | + with: |
| 79 | + name: ${{ matrix.npm-dir }} |
| 80 | + path: npm/${{ matrix.npm-dir }} |
| 81 | + |
| 82 | + publish: |
| 83 | + needs: build |
| 84 | + runs-on: ubuntu-latest |
| 85 | + environment: npm-publish |
| 86 | + permissions: |
| 87 | + contents: write |
| 88 | + id-token: write # Required for npm provenance |
| 89 | + env: |
| 90 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 91 | + steps: |
| 92 | + - uses: actions/checkout@v4 |
| 93 | + |
| 94 | + - name: Setup Node.js |
| 95 | + uses: actions/setup-node@v4 |
| 96 | + with: |
| 97 | + node-version: "20" |
| 98 | + registry-url: "https://registry.npmjs.org" |
| 99 | + |
| 100 | + - name: Download all artifacts |
| 101 | + uses: actions/download-artifact@v4 |
| 102 | + with: |
| 103 | + path: npm-artifacts |
| 104 | + |
| 105 | + - name: Prepare packages |
| 106 | + run: | |
| 107 | + # Copy built binaries to npm package directories |
| 108 | + for dir in npm-artifacts/*/; do |
| 109 | + name=$(basename "$dir") |
| 110 | + cp -r "$dir"/* "npm/$name/" |
| 111 | + done |
| 112 | +
|
| 113 | + # Copy main binary to zenv package for fallback |
| 114 | + mkdir -p npm/zenv/bin |
| 115 | + cp npm/linux-x64/bin/zenv npm/zenv/bin/ || true |
| 116 | +
|
| 117 | + - name: Update versions (manual dispatch) |
| 118 | + if: ${{ inputs.version }} |
| 119 | + run: | |
| 120 | + VERSION="${{ inputs.version }}" |
| 121 | + for pkg in npm/*/package.json; do |
| 122 | + sed -i "s/\"version\": \"[^\"]*\"/\"version\": \"$VERSION\"/" "$pkg" |
| 123 | + # Also update optionalDependencies versions in main package |
| 124 | + if [[ "$pkg" == "npm/zenv/package.json" ]]; then |
| 125 | + sed -i "s/@modlogtv\/zenv-\([^\"]*\)\": \"[^\"]*\"/@modlogtv\/zenv-\1\": \"$VERSION\"/g" "$pkg" |
| 126 | + fi |
| 127 | + done |
| 128 | + echo "Updated all packages to version $VERSION" |
| 129 | +
|
| 130 | + - name: Publish @modlogtv/zenv-linux-x64 |
| 131 | + if: ${{ !inputs.dry_run }} |
| 132 | + working-directory: npm/linux-x64 |
| 133 | + run: npm publish --access public --provenance |
| 134 | + |
| 135 | + - name: Publish @modlogtv/zenv-linux-arm64 |
| 136 | + if: ${{ !inputs.dry_run }} |
| 137 | + working-directory: npm/linux-arm64 |
| 138 | + run: npm publish --access public --provenance |
| 139 | + |
| 140 | + - name: Publish @modlogtv/zenv-darwin-x64 |
| 141 | + if: ${{ !inputs.dry_run }} |
| 142 | + working-directory: npm/darwin-x64 |
| 143 | + run: npm publish --access public --provenance |
| 144 | + |
| 145 | + - name: Publish @modlogtv/zenv-darwin-arm64 |
| 146 | + if: ${{ !inputs.dry_run }} |
| 147 | + working-directory: npm/darwin-arm64 |
| 148 | + run: npm publish --access public --provenance |
| 149 | + |
| 150 | + - name: Publish @modlogtv/zenv-win32-x64 |
| 151 | + if: ${{ !inputs.dry_run }} |
| 152 | + working-directory: npm/win32-x64 |
| 153 | + run: npm publish --access public --provenance |
| 154 | + |
| 155 | + - name: Publish @modlogtv/zenv |
| 156 | + if: ${{ !inputs.dry_run }} |
| 157 | + working-directory: npm/zenv |
| 158 | + run: npm publish --access public --provenance |
| 159 | + |
| 160 | + - name: Create GitHub Release |
| 161 | + if: ${{ !inputs.dry_run }} |
| 162 | + uses: softprops/action-gh-release@v1 |
| 163 | + with: |
| 164 | + tag_name: ${{ inputs.version && format('v{0}', inputs.version) || github.ref_name }} |
| 165 | + files: | |
| 166 | + npm-artifacts/*/bin/* |
| 167 | + generate_release_notes: true |
0 commit comments