name: Update chdman on: workflow_dispatch: inputs: version: description: "chdman npm version e.g. 0.289.0" required: true default: "0.289.0" dry_run: description: "Dry run publish to SourceForge" type: boolean required: false default: true permissions: contents: write pull-requests: write jobs: extract-and-publish: name: Extract chdman v${{ inputs.version }} runs-on: ubuntu-22.04 outputs: mame_version: ${{ steps.extract.outputs.mame_version }} strategy: fail-fast: false matrix: target: - os: linux arch: x86_64 pkg: "@emmercm/chdman-linux-x64" filename: chdman - os: linux arch: arm64 pkg: "@emmercm/chdman-linux-arm64" filename: chdman - os: macos arch: x86_64 pkg: "@emmercm/chdman-darwin-x64" filename: chdman - os: macos arch: arm64 pkg: "@emmercm/chdman-darwin-arm64" filename: chdman - os: windows arch: x86_64 pkg: "@emmercm/chdman-win32-x64" filename: chdman.exe steps: - name: Checkout OpenROM-bins uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: "20" - name: Extract & Verify npm Package id: extract env: RAW_VERSION: ${{ inputs.version }} PKG: ${{ matrix.target.pkg }} FILENAME: ${{ matrix.target.filename }} run: | python3 - <<'PY' import base64, hashlib, json, os, subprocess, sys raw_ver = os.environ["RAW_VERSION"] pkg = os.environ["PKG"] filename = os.environ["FILENAME"] print(f"Checking npm view {pkg}@{raw_ver} ...") info = json.loads(subprocess.check_output(["npm", "view", f"{pkg}@{raw_ver}", "--json"]).decode()) integrity = info.get("dist", {}).get("integrity", "") if not integrity: sys.exit(f"npm package {pkg}@{raw_ver} has no dist.integrity") print("npm dist.integrity:", integrity) tarball = subprocess.check_output(["npm", "pack", f"{pkg}@{raw_ver}"]).decode().strip() with open(tarball, "rb") as f: digest = hashlib.sha512(f.read()).digest() computed = "sha512-" + base64.b64encode(digest).decode() print("computed sha512: ", computed) if computed != integrity: sys.exit(f"Integrity mismatch for {tarball}: computed {computed} != npm {integrity}") subprocess.check_call(["tar", "-xzf", tarball]) os.makedirs("artifact_dir", exist_ok=True) extracted = os.path.join("package", "dist", filename) if not os.path.exists(extracted): sys.exit(f"Expected extracted binary at {extracted} not found!") os.rename(extracted, os.path.join("artifact_dir", filename)) # npm version is MAJOR.MINOR[.PATCH]; MAME releases are MAJOR.MINOR # (e.g. 0.289.0 -> mame0289), so drop any npm patch component. parts = raw_ver.split(".") mame_ver = "mame" + "".join(parts[:2]) with open(os.environ["GITHUB_OUTPUT"], "a") as f: f.write(f"mame_version={mame_ver}\n") PY - name: Upload Artifact uses: actions/upload-artifact@v4 with: name: chdman-${{ matrix.target.os }}-${{ matrix.target.arch }} path: artifact_dir/${{ matrix.target.filename }} if-no-files-found: error publish-linux-x64: needs: extract-and-publish uses: ./.github/workflows/publish-sourceforge.yml with: os: linux arch: x86_64 tool: chdman artifact_name: chdman-linux-x86_64 version: ${{ needs.extract-and-publish.outputs.mame_version }} toolchain: "npm package @emmercm/chdman-*" build_flavor: npm-extract dry_run: ${{ inputs.dry_run }} publish-linux-arm64: needs: extract-and-publish uses: ./.github/workflows/publish-sourceforge.yml with: os: linux arch: arm64 tool: chdman artifact_name: chdman-linux-arm64 version: ${{ needs.extract-and-publish.outputs.mame_version }} toolchain: "npm package @emmercm/chdman-*" build_flavor: npm-extract dry_run: ${{ inputs.dry_run }} publish-macos-x64: needs: extract-and-publish uses: ./.github/workflows/publish-sourceforge.yml with: os: macos arch: x86_64 tool: chdman artifact_name: chdman-macos-x86_64 version: ${{ needs.extract-and-publish.outputs.mame_version }} toolchain: "npm package @emmercm/chdman-*" build_flavor: npm-extract dry_run: ${{ inputs.dry_run }} publish-macos-arm64: needs: extract-and-publish uses: ./.github/workflows/publish-sourceforge.yml with: os: macos arch: arm64 tool: chdman artifact_name: chdman-macos-arm64 version: ${{ needs.extract-and-publish.outputs.mame_version }} toolchain: "npm package @emmercm/chdman-*" build_flavor: npm-extract dry_run: ${{ inputs.dry_run }} publish-windows-x64: needs: extract-and-publish uses: ./.github/workflows/publish-sourceforge.yml with: os: windows arch: x86_64 tool: chdman artifact_name: chdman-windows-x86_64 version: ${{ needs.extract-and-publish.outputs.mame_version }} toolchain: "npm package @emmercm/chdman-*" build_flavor: npm-extract dry_run: ${{ inputs.dry_run }}