fix: ci trigger on push, esbuild CJS bundle for pkg binary compilation #4
This file contains hidden or 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
| name: Release | |
| # FULLY AUTOMATED — every push to main. | |
| # CalVer auto-version → Tests → esbuild bundle → pkg binary → Publish. | |
| on: | |
| push: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| packages: write | |
| jobs: | |
| version: | |
| name: Calculate Version | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.calver.outputs.version }} | |
| tag: ${{ steps.calver.outputs.tag }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: { fetch-depth: 0, fetch-tags: true } | |
| - name: CalVer | |
| id: calver | |
| run: | | |
| Y=$(date +%Y); M=$(date +%-m) | |
| git fetch --tags 2>/dev/null || true | |
| H=0 | |
| for t in $(git tag -l "v${Y}.${M}.*"); do | |
| B=$(echo "$t" | sed "s/v${Y}.${M}.//") | |
| [ "$B" -gt "$H" ] 2>/dev/null && H=$B | |
| done | |
| V="${Y}.${M}.$((H+1))" | |
| echo "version=${V}" >> $GITHUB_OUTPUT | |
| echo "tag=v${V}" >> $GITHUB_OUTPUT | |
| echo "Version: ${V}" | |
| test: | |
| name: Test (Node ${{ matrix.node }}) | |
| runs-on: ubuntu-latest | |
| needs: [ version ] | |
| defaults: { run: { working-directory: ./cloudsync-cli } } | |
| strategy: | |
| matrix: | |
| node: ['18', '20', '22'] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node }} | |
| cache: npm | |
| cache-dependency-path: cloudsync-cli/package-lock.json | |
| - run: npm ci | |
| - run: npm test | |
| build-windows: | |
| name: Windows EXE | |
| runs-on: windows-latest | |
| needs: [ test ] | |
| defaults: { run: { working-directory: ./cloudsync-cli } } | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| cache: npm | |
| cache-dependency-path: cloudsync-cli/package-lock.json | |
| - run: npm ci | |
| - run: npm run build | |
| - run: npm install -g @yao-pkg/pkg | |
| - run: pkg dist/bundle.cjs -t node22-win-x64 -o cloudsync.exe | |
| - run: .\cloudsync.exe --version | |
| - run: | | |
| mkdir release-assets | |
| copy cloudsync.exe release-assets\ | |
| copy installer\CloudSync-Setup.bat release-assets\ | |
| copy installer\CloudSync.iss release-assets\ | |
| copy README.md release-assets\ | |
| copy LICENSE release-assets\ | |
| Compress-Archive -Path release-assets\* -DestinationPath cloudsync-windows-x64.zip | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: windows-build | |
| path: | | |
| cloudsync-cli/cloudsync.exe | |
| cloudsync-cli/cloudsync-windows-x64.zip | |
| cloudsync-cli/installer/CloudSync-Setup.bat | |
| cloudsync-cli/installer/CloudSync.iss | |
| retention-days: 7 | |
| build-linux: | |
| name: Linux Binary | |
| runs-on: ubuntu-latest | |
| needs: [ test ] | |
| defaults: { run: { working-directory: ./cloudsync-cli } } | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| cache: npm | |
| cache-dependency-path: cloudsync-cli/package-lock.json | |
| - run: npm ci | |
| - run: npm run build | |
| - run: npm install -g @yao-pkg/pkg | |
| - run: pkg dist/bundle.cjs -t node22-linux-x64 -o cloudsync | |
| - run: chmod +x cloudsync && ./cloudsync --version | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: linux-build | |
| path: cloudsync-cli/cloudsync | |
| retention-days: 7 | |
| build-macos: | |
| name: macOS Binary | |
| runs-on: macos-latest | |
| needs: [ test ] | |
| defaults: { run: { working-directory: ./cloudsync-cli } } | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| cache: npm | |
| cache-dependency-path: cloudsync-cli/package-lock.json | |
| - run: npm ci | |
| - run: npm run build | |
| - run: npm install -g @yao-pkg/pkg | |
| - run: pkg dist/bundle.cjs -t node22-macos-x64 -o cloudsync | |
| - run: chmod +x cloudsync && ./cloudsync --version | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: macos-build | |
| path: cloudsync-cli/cloudsync | |
| retention-days: 7 | |
| publish: | |
| name: Publish & Release | |
| runs-on: ubuntu-latest | |
| needs: [ version, build-windows, build-linux, build-macos ] | |
| defaults: { run: { working-directory: ./cloudsync-cli } } | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: { fetch-depth: 0, fetch-tags: true } | |
| - uses: actions/download-artifact@v4 | |
| with: { name: windows-build, path: assets/windows } | |
| - uses: actions/download-artifact@v4 | |
| with: { name: linux-build, path: assets/linux } | |
| - uses: actions/download-artifact@v4 | |
| with: { name: macos-build, path: assets/macos } | |
| - name: Set version | |
| run: | | |
| V=${{ needs.version.outputs.version }} | |
| npm pkg set version=$V | |
| echo "export const VERSION = '$V';" > src/version.mjs | |
| - name: Create git tag | |
| run: | | |
| git config user.name "github-actions" | |
| git config user.email "actions@github.com" | |
| git add package.json src/version.mjs | |
| git commit -m "release: ${{ needs.version.outputs.version }}" || true | |
| git tag ${{ needs.version.outputs.tag }} | |
| git push origin HEAD:main ${{ needs.version.outputs.tag }} | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| registry-url: 'https://registry.npmjs.org' | |
| cache: npm | |
| cache-dependency-path: cloudsync-cli/package-lock.json | |
| - run: npm ci | |
| - run: npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Publish to GPR | |
| run: | | |
| npm pkg set name="@tech4file/cloudsync-cli" | |
| npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Checksums | |
| run: | | |
| cd assets | |
| find . -type f ! -name '*.zip' ! -name '*.bat' ! -name '*.iss' ! -name '*.md' ! -name 'LICENSE' \ | |
| -exec sha256sum {} \; > checksums.txt | |
| - uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ needs.version.outputs.tag }} | |
| name: ${{ needs.version.outputs.version }} | |
| generate_release_notes: true | |
| files: | | |
| assets/windows/cloudsync.exe | |
| assets/windows/cloudsync-windows-x64.zip | |
| assets/windows/CloudSync-Setup.bat | |
| assets/windows/CloudSync.iss | |
| assets/linux/cloudsync | |
| assets/macos/cloudsync | |
| assets/checksums.txt | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |