|
1 | | -name: Release |
| 1 | +name: CI & Release |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
| 5 | + branches: ["main"] |
5 | 6 | tags: |
6 | 7 | - "v*.*.*" |
| 8 | + pull_request: |
| 9 | + branches: ["main"] |
7 | 10 | workflow_dispatch: |
8 | 11 |
|
9 | 12 | permissions: |
10 | 13 | contents: write |
11 | 14 | id-token: write |
12 | 15 |
|
13 | | -jobs: |
14 | | - build-wasm: |
15 | | - name: Build WASM package for npm |
16 | | - runs-on: ubuntu-latest |
17 | | - |
18 | | - steps: |
19 | | - - name: Checkout code |
20 | | - uses: actions/checkout@v4 |
21 | | - |
22 | | - - name: Install Rust toolchain |
23 | | - uses: dtolnay/rust-toolchain@stable |
24 | | - |
25 | | - - name: Install wasm-pack |
26 | | - run: | |
27 | | - cargo install wasm-pack |
28 | | -
|
29 | | - - name: Build WASM package |
30 | | - run: | |
31 | | - wasm-pack build --release --target web --out-name html2json . |
32 | | -
|
33 | | - - name: Upload WASM artifacts |
34 | | - uses: actions/upload-artifact@v4 |
35 | | - with: |
36 | | - name: html2json-wasm |
37 | | - path: pkg/* |
38 | | - |
39 | | - publish-npm: |
40 | | - name: Publish to npm |
41 | | - needs: build-wasm |
42 | | - runs-on: ubuntu-latest |
| 16 | +concurrency: |
| 17 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 18 | + cancel-in-progress: true |
43 | 19 |
|
44 | | - steps: |
45 | | - - name: Checkout code |
46 | | - uses: actions/checkout@v4 |
47 | | - |
48 | | - - name: Download WASM artifacts |
49 | | - uses: actions/download-artifact@v4 |
50 | | - with: |
51 | | - name: html2json-wasm |
52 | | - path: pkg |
53 | | - |
54 | | - - name: Setup Node.js |
55 | | - uses: actions/setup-node@v4 |
56 | | - with: |
57 | | - node-version: "24" |
58 | | - registry-url: "https://registry.npmjs.org" |
| 20 | +env: |
| 21 | + CARGO_TERM_COLOR: always |
59 | 22 |
|
60 | | - - name: Publish to npm |
61 | | - run: | |
62 | | - if [ -n "${{ secrets.NPM_TOKEN }}" ]; then |
63 | | - npm publish --access public |
64 | | - else |
65 | | - echo "NPM_TOKEN not set, skipping npm publish" |
66 | | - fi |
67 | | - env: |
68 | | - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
69 | | - |
70 | | - build-release: |
71 | | - name: Build release binaries |
| 23 | +jobs: |
| 24 | + build: |
| 25 | + name: Build & Test (${{ matrix.os }}) |
72 | 26 | runs-on: ${{ matrix.os }} |
73 | 27 | strategy: |
74 | 28 | matrix: |
75 | 29 | include: |
76 | 30 | - os: ubuntu-latest |
77 | 31 | target: x86_64-unknown-linux-gnu |
78 | | - archive: tar.gz |
79 | | - - os: ubuntu-latest |
80 | | - target: aarch64-unknown-linux-gnu |
81 | | - archive: tar.gz |
82 | 32 | - os: macos-latest |
83 | 33 | target: x86_64-apple-darwin |
84 | | - archive: tar.gz |
85 | 34 | - os: macos-latest |
86 | 35 | target: aarch64-apple-darwin |
87 | | - archive: tar.gz |
88 | 36 | - os: windows-latest |
89 | 37 | target: x86_64-pc-windows-msvc |
90 | | - archive: zip |
91 | 38 |
|
92 | 39 | steps: |
93 | | - - name: Checkout code |
94 | | - uses: actions/checkout@v4 |
| 40 | + - uses: actions/checkout@v4 |
| 41 | + |
| 42 | + - name: Cache cargo |
| 43 | + uses: actions/cache@v4 |
| 44 | + with: |
| 45 | + path: | |
| 46 | + ~/.cargo/registry |
| 47 | + ~/.cargo/git |
| 48 | + target |
| 49 | + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} |
95 | 50 |
|
96 | 51 | - name: Install Rust toolchain |
97 | 52 | uses: dtolnay/rust-toolchain@stable |
98 | 53 | with: |
99 | 54 | targets: ${{ matrix.target }} |
100 | 55 |
|
101 | | - - name: Install cross-compilation tools (aarch64-linux) |
102 | | - if: matrix.target == 'aarch64-unknown-linux-gnu' |
103 | | - run: | |
104 | | - sudo apt-get update |
105 | | - sudo apt-get install -y gcc-aarch64-linux-gnu |
| 56 | + - name: Build |
| 57 | + run: cargo build --release --target ${{ matrix.target }} --features cli |
106 | 58 |
|
107 | | - - name: Build binary |
108 | | - run: | |
109 | | - cargo build --release --target ${{ matrix.target }} --features cli |
110 | | - env: |
111 | | - CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc |
112 | | - CC_aarch64_unknown_linux_gnu: aarch64-linux-gnu-gcc |
| 59 | + - name: Run tests |
| 60 | + run: cargo test --release --target ${{ matrix.target }} |
113 | 61 |
|
114 | | - - name: Prepare archive (Unix) |
115 | | - if: runner.os != 'Windows' |
116 | | - run: | |
117 | | - cd target/${{ matrix.target }}/release |
118 | | - tar czf ../../../html2json-${{ matrix.target }}.tar.gz html2json |
119 | | - cd - |
| 62 | + - name: Upload binary artifact |
| 63 | + uses: actions/upload-artifact@v4 |
| 64 | + with: |
| 65 | + name: html2json-${{ matrix.target }} |
| 66 | + path: target/${{ matrix.target }}/release/html2json* |
| 67 | + if-no-files-found: error |
| 68 | + |
| 69 | + wasm: |
| 70 | + name: Build WASM |
| 71 | + runs-on: ubuntu-latest |
| 72 | + |
| 73 | + steps: |
| 74 | + - uses: actions/checkout@v4 |
| 75 | + |
| 76 | + - name: Cache cargo |
| 77 | + uses: actions/cache@v4 |
| 78 | + with: |
| 79 | + path: | |
| 80 | + ~/.cargo/registry |
| 81 | + ~/.cargo/git |
| 82 | + target |
| 83 | + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} |
| 84 | + |
| 85 | + - name: Install Rust toolchain |
| 86 | + uses: dtolnay/rust-toolchain@stable |
| 87 | + |
| 88 | + - name: Install wasm-pack |
| 89 | + run: cargo install wasm-pack |
| 90 | + |
| 91 | + - name: Build WASM |
| 92 | + run: wasm-pack build --release --target web --out-name html2json --scope qretaio -- --features wasm |
120 | 93 |
|
121 | | - - name: Prepare archive (Windows) |
122 | | - if: runner.os == 'Windows' |
| 94 | + - name: Add auto-init wrapper |
123 | 95 | run: | |
124 | | - Compress-Archive -Path target/${{ matrix.target }}/release/html2json.exe -DestinationPath html2json-${{ matrix.target }}.zip |
| 96 | + cp scripts/wrapper.js pkg/index.js |
| 97 | + # Update package.json to use wrapper as entry point |
| 98 | + npm pkg set main="index.js" --prefix pkg |
| 99 | + npm pkg set files[3]="index.js" --prefix pkg |
125 | 100 |
|
126 | | - - name: Upload artifacts |
| 101 | + - name: Upload WASM artifact |
127 | 102 | uses: actions/upload-artifact@v4 |
128 | 103 | with: |
129 | | - name: html2json-${{ matrix.target }} |
130 | | - path: html2json-${{ matrix.target }}.${{ matrix.archive }} |
| 104 | + name: html2json |
| 105 | + path: pkg/* |
| 106 | + if-no-files-found: error |
131 | 107 |
|
132 | | - publish-release: |
133 | | - name: Publish GitHub release |
134 | | - needs: [build-release, build-wasm] |
| 108 | + release: |
| 109 | + name: Release |
135 | 110 | runs-on: ubuntu-latest |
| 111 | + needs: [build, wasm] |
| 112 | + if: startsWith(github.ref, 'refs/tags/v') |
136 | 113 |
|
137 | 114 | steps: |
138 | | - - name: Checkout code |
139 | | - uses: actions/checkout@v4 |
140 | | - |
141 | 115 | - name: Download all artifacts |
142 | 116 | uses: actions/download-artifact@v4 |
143 | 117 | with: |
144 | 118 | path: artifacts |
145 | 119 |
|
146 | | - - name: Create WASM archive |
| 120 | + - name: Setup Node.js |
| 121 | + uses: actions/setup-node@v4 |
| 122 | + with: |
| 123 | + node-version: "24" |
| 124 | + registry-url: "https://registry.npmjs.org" |
| 125 | + |
| 126 | + - name: Create archives |
147 | 127 | run: | |
148 | | - cd artifacts/html2json-wasm |
149 | | - tar czf ../../html2json-wasm.tar.gz . |
150 | | - cd ../.. |
| 128 | +
|
| 129 | + # List downloaded artifacts for debugging |
| 130 | + echo "Downloaded artifacts:" |
| 131 | + ls -la |
| 132 | + cd artifacts |
| 133 | +
|
| 134 | +
|
| 135 | + # Create WASM archive (handle scoped package name) |
| 136 | + if [ -d "html2json" ]; then |
| 137 | + cd html2json |
| 138 | + # Check if scoped package directory exists inside |
| 139 | + if [ -d "@qretaio" ]; then |
| 140 | + cd "@qretaio" |
| 141 | + tar czf ../../../html2json-wasm.tar.gz html2json |
| 142 | + else |
| 143 | + tar czf ../../html2json-wasm.tar.gz . |
| 144 | + fi |
| 145 | + cd ../.. |
| 146 | + fi |
| 147 | +
|
| 148 | + # Create binary archives |
| 149 | + for dir in html2json-*/; do |
| 150 | + target="${dir#html2json-}" |
| 151 | + target="${target%/}" |
| 152 | + cd "$dir" |
| 153 | +
|
| 154 | + if [[ "$target" == *"windows"* ]]; then |
| 155 | + Compress-Archive -Path html2json.exe -DestinationPath "../../html2json-$target.zip" |
| 156 | + else |
| 157 | + tar czf "../../html2json-$target.tar.gz" html2json |
| 158 | + fi |
| 159 | +
|
| 160 | + cd .. |
| 161 | + done |
151 | 162 |
|
152 | 163 | - name: Create release |
153 | 164 | uses: softprops/action-gh-release@v2 |
154 | 165 | with: |
155 | 166 | files: | |
156 | | - html2json-wasm.tar.gz |
157 | | - artifacts/*/* |
| 167 | + html2json-* |
158 | 168 | generate_release_notes: true |
159 | 169 | env: |
160 | 170 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 171 | + |
| 172 | + - name: Publish to npm |
| 173 | + working-directory: artifacts/html2json |
| 174 | + run: npm publish --access public |
0 commit comments