diff --git a/.github/workflows/cargo-publish.yaml b/.github/workflows/cargo-publish.yaml deleted file mode 100644 index c09611a..0000000 --- a/.github/workflows/cargo-publish.yaml +++ /dev/null @@ -1,83 +0,0 @@ -name: Cargo Crate Release -on: - push: - branches: - - main -# Serialize with NPM Packages Release: both workflows commit version -# bumps and push back to main, so concurrent runs collide on push. -concurrency: - group: package-release -jobs: - release: - if: ${{ github.ref == 'refs/heads/main' && !startsWith(github.event.head_commit.message, 'Cargo Crate Release') }} - runs-on: ubuntu-latest - permissions: - contents: write - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - ssh-key: ${{ secrets.PUBLISH_PRIVATE_KEY }} - - uses: nixbuild/nix-quick-install-action@v30 - with: - nix_conf: | - keep-env-derivations = true - keep-outputs = true - - name: Restore and save Nix store - uses: nix-community/cache-nix-action@v6 - with: - primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/flake.lock') }} - restore-prefixes-first-match: nix-${{ runner.os }}- - gc-max-store-size-linux: 1G - - run: nix develop -c forge soldeer install - - run: nix develop -c cargo test -p rain-math-float - # Hash the crate tarball that would be published. - - name: Get New Hash - run: | - NEW_HASH=$(nix develop -c cargo package -p rain-math-float --allow-dirty --quiet --list | LC_ALL=C sort | sha256sum | cut -d' ' -f1) - echo "NEW_HASH=$NEW_HASH" >> $GITHUB_ENV - # Hash the file list of the latest published version on crates.io. - - name: Get Old Hash - run: | - OLD_VERSION=$(curl -fsSL "https://crates.io/api/v1/crates/rain-math-float" | python3 -c "import sys, json; print(json.load(sys.stdin)['crate']['max_version'])" 2>/dev/null || echo "none") - if [ "$OLD_VERSION" = "none" ]; then - OLD_HASH="none" - else - curl -fsSL "https://crates.io/api/v1/crates/rain-math-float/$OLD_VERSION/download" -o /tmp/old.crate - OLD_HASH=$(tar -tzf /tmp/old.crate 2>/dev/null | LC_ALL=C sort | sha256sum | cut -d' ' -f1) - fi - echo "OLD_HASH=$OLD_HASH" >> $GITHUB_ENV - - name: Git Config - if: ${{ env.OLD_HASH != env.NEW_HASH }} - run: | - git config --global user.email "${{ secrets.CI_GIT_EMAIL }}" - git config --global user.name "${{ secrets.CI_GIT_USER }}" - - name: Publish to crates.io - if: ${{ env.OLD_HASH != env.NEW_HASH }} - run: nix develop -c cargo release --no-confirm --execute --no-tag -p rain-math-float alpha - env: - CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} - - name: Get Version - if: ${{ env.OLD_HASH != env.NEW_HASH }} - run: echo "NEW_VERSION=v$(cargo pkgid -p rain-math-float | cut -d@ -f2)" >> $GITHUB_ENV - - name: Push Commit - if: ${{ env.OLD_HASH != env.NEW_HASH }} - run: git push origin - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Tag - if: ${{ env.OLD_HASH != env.NEW_HASH }} - run: git tag crate-${{ env.NEW_VERSION }} - - name: Push Tag - if: ${{ env.OLD_HASH != env.NEW_HASH }} - run: git push origin crate-${{ env.NEW_VERSION }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Create GitHub Release - if: ${{ env.OLD_HASH != env.NEW_HASH }} - uses: softprops/action-gh-release@v2 - with: - tag_name: crate-${{ env.NEW_VERSION }} - name: Cargo Crate Release ${{ env.NEW_VERSION }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/npm-package-release.yaml b/.github/workflows/npm-package-release.yaml deleted file mode 100644 index 0f76e22..0000000 --- a/.github/workflows/npm-package-release.yaml +++ /dev/null @@ -1,103 +0,0 @@ -name: NPM Packages Release -on: - push: - branches: - - main -# Serialize with Cargo Crate Release: both workflows commit version -# bumps and push back to main, so concurrent runs collide on push. -concurrency: - group: package-release -jobs: - release: - if: ${{ github.ref == 'refs/heads/main' && !startsWith(github.event.head_commit.message, 'NPM Package Release') }} - runs-on: ubuntu-latest - permissions: - id-token: write - contents: write - outputs: - version: ${{ env.NEW_VERSION }} - steps: - - uses: actions/checkout@v4 - with: - ssh-key: ${{ secrets.PUBLISH_PRIVATE_KEY }} - fetch-depth: 0 - - uses: DeterminateSystems/nix-installer-action@main - with: - determinate: true - - uses: DeterminateSystems/flakehub-cache-action@main - - name: Install NodeJS v22 - uses: actions/setup-node@v4 - with: - node-version: 22 - cache: "npm" - - run: nix develop -c forge soldeer install - - name: Test JS/TS Binding - run: nix develop -c test-js-bindings - - name: Git Config - run: | - git config --global user.email "${{ secrets.CI_GIT_EMAIL }}" - git config --global user.name "${{ secrets.CI_GIT_USER }}" - # get hash of latest published pkgs from npm and concat them - - name: Get Old Hash - run: | - OLD_HASH=$(npm view @rainlanguage/float@latest dist.shasum 2>/dev/null || echo "none") - echo "OLD_HASH=$OLD_HASH" >> $GITHUB_ENV - echo "old hash: $OLD_HASH" - # calc hash of current workspace pkgs by packing them and concat them - - name: Get New Hash - run: | - NEW_HASH=$(npm pack --silent | xargs shasum | cut -c1-40) - echo "NEW_HASH=$NEW_HASH" >> $GITHUB_ENV - echo "new hash: $NEW_HASH" - rm -f *.tgz - # from here on, we'll skip if OLD_HASH and NEW_HASH are the same (ie no publish) - # this means we need to skip every step by using an if statement. - # set npm version - - name: Set Version - if: ${{ env.OLD_HASH != env.NEW_HASH }} - run: | - NEW_VERSION=$(npm version prerelease --preid alpha --no-git-tag-version) - echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV - # Commit changes and tag - - name: Commit And Tag - if: ${{ env.OLD_HASH != env.NEW_HASH }} - run: | - git add "package.json" - git add "package-lock.json" - git commit -m "NPM Package Release v${{ env.NEW_VERSION }}" - git tag npm-v${{ env.NEW_VERSION }} - # Push the commit to remote - - name: Push Changes To Remote - if: ${{ env.OLD_HASH != env.NEW_HASH }} - run: | - git push origin - git push -u origin npm-v${{ env.NEW_VERSION }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # Create float npm package tarball - - name: Create float NPM Package Tarball - if: ${{ env.OLD_HASH != env.NEW_HASH }} - run: echo "NPM_PACKAGE=$(npm pack --silent)" >> $GITHUB_ENV - - name: Rename float NPM Package Tarball - if: ${{ env.OLD_HASH != env.NEW_HASH }} - run: mv ${{ env.NPM_PACKAGE }} float_npm_package_${{ env.NEW_VERSION }}.tgz - # publish float pkg to npm - - name: Publish float pkg To NPM - if: ${{ env.OLD_HASH != env.NEW_HASH }} - uses: JS-DevTools/npm-publish@v3 - with: - token: ${{ secrets.NPM_TOKEN }} - access: public - package: float_npm_package_${{ env.NEW_VERSION }}.tgz - # Create gitHub release with tarballs - - name: Create GitHub Release with float pkg - if: ${{ env.OLD_HASH != env.NEW_HASH }} - id: gh_release - uses: softprops/action-gh-release@v2 - with: - tag_name: npm-v${{ env.NEW_VERSION }} - name: NPM Package Release v${{ env.NEW_VERSION }} - files: | - float_npm_package_${{ env.NEW_VERSION }}.tgz - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/package-release.yaml b/.github/workflows/package-release.yaml new file mode 100644 index 0000000..1ebbc90 --- /dev/null +++ b/.github/workflows/package-release.yaml @@ -0,0 +1,128 @@ +name: Package Release +on: + push: + branches: + - main +jobs: + release: + if: ${{ github.ref == 'refs/heads/main' && !startsWith(github.event.head_commit.message, 'Package Release') }} + runs-on: ubuntu-latest + permissions: + id-token: write + contents: write + steps: + - uses: actions/checkout@v4 + with: + ssh-key: ${{ secrets.PUBLISH_PRIVATE_KEY }} + fetch-depth: 0 + - uses: nixbuild/nix-quick-install-action@v30 + with: + nix_conf: | + keep-env-derivations = true + keep-outputs = true + - name: Restore and save Nix store + uses: nix-community/cache-nix-action@v6 + with: + primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/flake.lock') }} + restore-prefixes-first-match: nix-${{ runner.os }}- + gc-max-store-size-linux: 1G + - name: Install NodeJS v22 + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: "npm" + - run: nix develop -c forge soldeer install + - name: Test JS/TS bindings + run: nix develop -c test-js-bindings + - name: Cargo test + run: nix develop -c cargo test -p rain-math-float + - name: Git Config + run: | + git config --global user.email "${{ secrets.CI_GIT_EMAIL }}" + git config --global user.name "${{ secrets.CI_GIT_USER }}" + # NPM hash detection + - name: NPM hashes + id: npm + run: | + OLD=$(npm view @rainlanguage/float@latest dist.shasum 2>/dev/null || echo "none") + NEW=$(npm pack --silent | xargs shasum | cut -c1-40) + rm -f *.tgz + echo "old=$OLD" >> $GITHUB_OUTPUT + echo "new=$NEW" >> $GITHUB_OUTPUT + if [ "$OLD" = "$NEW" ]; then echo "changed=false" >> $GITHUB_OUTPUT; else echo "changed=true" >> $GITHUB_OUTPUT; fi + # Cargo hash detection + - name: Cargo hashes + id: cargo + run: | + NEW=$(nix develop -c cargo package -p rain-math-float --allow-dirty --quiet --list | LC_ALL=C sort | sha256sum | cut -d' ' -f1) + OLD_VERSION=$(curl -fsSL "https://crates.io/api/v1/crates/rain-math-float" | python3 -c "import sys, json; print(json.load(sys.stdin)['crate']['max_version'])" 2>/dev/null || echo "none") + if [ "$OLD_VERSION" = "none" ]; then + OLD="none" + else + curl -fsSL "https://crates.io/api/v1/crates/rain-math-float/$OLD_VERSION/download" -o /tmp/old.crate + OLD=$(tar -tzf /tmp/old.crate 2>/dev/null | LC_ALL=C sort | sha256sum | cut -d' ' -f1) + fi + echo "old=$OLD" >> $GITHUB_OUTPUT + echo "new=$NEW" >> $GITHUB_OUTPUT + if [ "$OLD" = "$NEW" ]; then echo "changed=false" >> $GITHUB_OUTPUT; else echo "changed=true" >> $GITHUB_OUTPUT; fi + # NPM version bump + tag (no push yet — batch with cargo) + - name: Bump NPM version + if: ${{ steps.npm.outputs.changed == 'true' }} + run: | + NEW=$(npm version prerelease --preid alpha --no-git-tag-version) + echo "NPM_VERSION=$NEW" >> $GITHUB_ENV + git add package.json package-lock.json + # Cargo version bump + tag (no push yet — batch with npm) + - name: Bump Cargo version + if: ${{ steps.cargo.outputs.changed == 'true' }} + run: | + nix develop -c cargo release --no-confirm --execute --no-tag --no-push -p rain-math-float alpha + echo "CARGO_VERSION=v$(cargo pkgid -p rain-math-float | cut -d@ -f2)" >> $GITHUB_ENV + # Single push of both bump commits (cargo-release made its own commit; + # the npm bump is staged into a separate commit here). + - name: Commit and push version bumps + if: ${{ steps.npm.outputs.changed == 'true' || steps.cargo.outputs.changed == 'true' }} + run: | + if [ "${{ steps.npm.outputs.changed }}" = "true" ]; then + git commit -m "Package Release npm-${{ env.NPM_VERSION }}" + fi + if [ -n "${{ env.NPM_VERSION }}" ]; then git tag npm-${{ env.NPM_VERSION }}; fi + if [ -n "${{ env.CARGO_VERSION }}" ]; then git tag crate-${{ env.CARGO_VERSION }}; fi + git push origin main + git push origin --tags + # NPM publish + - name: NPM pack + if: ${{ steps.npm.outputs.changed == 'true' }} + run: | + TARBALL=$(npm pack --silent) + mv "$TARBALL" float_npm_package_${{ env.NPM_VERSION }}.tgz + - name: Publish to NPM + if: ${{ steps.npm.outputs.changed == 'true' }} + uses: JS-DevTools/npm-publish@v3 + with: + token: ${{ secrets.NPM_TOKEN }} + access: public + package: float_npm_package_${{ env.NPM_VERSION }}.tgz + # Cargo publish + - name: Publish to crates.io + if: ${{ steps.cargo.outputs.changed == 'true' }} + run: nix develop -c cargo publish -p rain-math-float + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + - name: GitHub Release (npm) + if: ${{ steps.npm.outputs.changed == 'true' }} + uses: softprops/action-gh-release@v2 + with: + tag_name: npm-${{ env.NPM_VERSION }} + name: NPM Package Release ${{ env.NPM_VERSION }} + files: float_npm_package_${{ env.NPM_VERSION }}.tgz + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: GitHub Release (cargo) + if: ${{ steps.cargo.outputs.changed == 'true' }} + uses: softprops/action-gh-release@v2 + with: + tag_name: crate-${{ env.CARGO_VERSION }} + name: Cargo Crate Release crate-${{ env.CARGO_VERSION }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}