diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8a2e736..0d52d5b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,14 +33,30 @@ jobs: GITHUB_TOKEN: ${{ github.token }} CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} + - name: Install Determinate Nix + if: ${{ steps.release-plz.outputs.prs_created == 'true' || steps.release-plz.outputs.releases_created == 'true' }} + uses: DeterminateSystems/determinate-nix-action@2a0be2498974c2b6327e19780488744384637d88 # v3.21.7 + with: + extra-conf: lazy-trees = true + + - name: Set up FlakeHub Cache + if: ${{ steps.release-plz.outputs.prs_created == 'true' || steps.release-plz.outputs.releases_created == 'true' }} + uses: DeterminateSystems/flakehub-cache-action@3be0931021788e3bb4df65f59a555039c2fa2d46 # v3.21.7 + + - name: Enter Nix devshell + if: ${{ steps.release-plz.outputs.prs_created == 'true' || steps.release-plz.outputs.releases_created == 'true' }} + uses: nicknovitski/nix-develop@9be7cfb4b10451d3390a75dc18ad0465bed4932a # v1.2.1 + - name: Bump changelog versions if: ${{ steps.release-plz.outputs.prs_created == 'true' }} env: GH_TOKEN: ${{ github.token }} - run: scripts/bump-changelogs '${{ steps.release-plz.outputs.pr }}' + RELEASE_PLZ_PR_JSON: ${{ steps.release-plz.outputs.pr }} + run: x52-bump-changelogs - name: Update release notes if: ${{ steps.release-plz.outputs.releases_created == 'true' }} env: GH_TOKEN: ${{ github.token }} - run: scripts/update-release-notes '${{ steps.release-plz.outputs.releases }}' + RELEASE_PLZ_RELEASES_JSON: ${{ steps.release-plz.outputs.releases }} + run: x52-update-release-notes diff --git a/flake.lock b/flake.lock index b57e78a..ad8c19a 100644 --- a/flake.lock +++ b/flake.lock @@ -66,11 +66,11 @@ ] }, "locked": { - "lastModified": 1716077176, - "narHash": "sha256-CJLStpZHEVZ+fgXG3H61R97KzQePkdNXpnhkDBtHUec=", + "lastModified": 1784633661, + "narHash": "sha256-eOrF1y0svdniEnjIuuvkzOv6z/ltBepYjApINcDY1Xg=", "owner": "x52dev", "repo": "nix", - "rev": "4afdfa74f1bef9a7e2e99498c47a25b0753a43e0", + "rev": "5e898b3d4b5bb9801964488d6ab4a6ed445c1809", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 1febf56..67748c1 100644 --- a/flake.nix +++ b/flake.nix @@ -20,7 +20,10 @@ formatter = pkgs.nixpkgs-fmt; devShells.default = pkgs.mkShell { - buildInputs = [ x52just ]; + buildInputs = [ + x52just + inputs'.x52.packages.x52-release-tools + ]; packages = [ config.formatter diff --git a/scripts/bump-changelogs b/scripts/bump-changelogs deleted file mode 100755 index 336bfd7..0000000 --- a/scripts/bump-changelogs +++ /dev/null @@ -1,139 +0,0 @@ -#!/usr/bin/env bash - -# Updates changelog versions indicated by release-plz. - -set -eEuo pipefail - -WORKSPACE_METADATA="$(cargo metadata --format-version=1 --no-deps)" - -function package_dir_for() { - local package_name="$1" - local manifest_path - - manifest_path="$( - echo "$WORKSPACE_METADATA" \ - | jq -r --arg package_name "$package_name" '.packages[] | select(.name == $package_name) | .manifest_path' \ - | head -n 1 - )" - - if [[ -z "$manifest_path" || "$manifest_path" == "null" ]]; then - echo "Could not determine package directory for $package_name" >&2 - return 1 - fi - - dirname "$manifest_path" -} - -function bump_changelog_version() { - local package_dir="$1" - local version="$2" - - local changelog_file="${package_dir}/CHANGELOG.md" - local readme_file="${package_dir}/README.md" - local unreleased_line - local next_heading_line - local previous_version - local change_chunk_file - local line_count - - if [[ ! -f "$changelog_file" ]]; then - echo "Skipping ${package_dir}: no CHANGELOG.md" - return 0 - fi - - if awk -v version="$version" '$0 == "## " version { found = 1 } END { exit !found }' "$changelog_file"; then - echo "Skipping ${changelog_file}: already contains ${version}" - return 0 - fi - - unreleased_line="$(awk '/^## Unreleased$/ { print NR; exit }' "$changelog_file")" - if [[ -z "$unreleased_line" ]]; then - echo "Skipping ${changelog_file}: no '## Unreleased' heading" - return 0 - fi - - next_heading_line="$( - awk -v start="$unreleased_line" 'NR > start && /^## / { print NR; exit }' "$changelog_file" - )" - if [[ -z "$next_heading_line" ]]; then - echo "Skipping ${changelog_file}: no version headings found after '## Unreleased'" - return 0 - fi - - previous_version="$(sed -n "${next_heading_line}s/^## //p" "$changelog_file")" - change_chunk_file="$(mktemp)" - line_count="$(wc -l < "$changelog_file" | awk '{ print $1 }')" - - echo "${changelog_file} -> ${version}" - - sed -n "$((unreleased_line + 1)),$((next_heading_line - 1))p" "$changelog_file" \ - | awk ' - { - lines[NR] = $0 - } - END { - first = 1 - while (first <= NR && lines[first] ~ /^[[:space:]]*$/) { - first++ - } - - last = NR - while (last >= first && lines[last] ~ /^[[:space:]]*$/) { - last-- - } - - for (i = first; i <= last; i++) { - print lines[i] - } - } - ' >"$change_chunk_file" - - if [[ "$(wc -w "$change_chunk_file" | awk '{ print $1 }')" == "0" ]]; then - printf '%s\n' "- No significant changes since \`${previous_version}\`." >"$change_chunk_file" - fi - - ( - sed -n "1,${unreleased_line}p" "$changelog_file" - echo - echo "## $version" - echo - sed -n '1,$p' "$change_chunk_file" - echo - sed -n "${next_heading_line},${line_count}p" "$changelog_file" - ) >"$changelog_file.bak" - - mv "$changelog_file.bak" "$changelog_file" - rm -f "$change_chunk_file" - - if [[ -f "$readme_file" && -n "$previous_version" ]]; then - sed -i.bak -E "s#([=/])${previous_version}([/)])#\\1${version}\\2#g" "$readme_file" - rm -f "${readme_file}.bak" - fi -} - -RELEASE_PLZ_PR_JSON="$1" -PR_NUMBER="$(echo "$RELEASE_PLZ_PR_JSON" | jq -r '.number')" - -if [[ -n "$PR_NUMBER" && "$PR_NUMBER" != "null" ]]; then - gh pr checkout "$PR_NUMBER" - WORKSPACE_METADATA="$(cargo metadata --format-version=1 --no-deps)" -fi - -specs="$(echo "$RELEASE_PLZ_PR_JSON" | jq -r '.releases[] | "\(.package_name):\(.version)"')" - -for spec in $specs; do - name="$(echo "$spec" | cut -d: -f1)" - version="$(echo "$spec" | cut -d: -f2)" - package_dir="$(package_dir_for "$name")" - - bump_changelog_version "$package_dir" "$version" -done - -if [[ -n "$PR_NUMBER" && "$PR_NUMBER" != "null" ]]; then - git add --all - - if ! git diff --cached --quiet; then - git commit -m "docs: update changelog versions" - git push - fi -fi diff --git a/scripts/update-release-notes b/scripts/update-release-notes deleted file mode 100755 index 5f755e1..0000000 --- a/scripts/update-release-notes +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env bash - -# Updates GitHub release notes from crate changelogs. - -set -eEuo pipefail - -WORKSPACE_METADATA="$(cargo metadata --format-version=1 --no-deps)" - -function package_dir_for() { - local package_name="$1" - local manifest_path - - manifest_path="$( - echo "$WORKSPACE_METADATA" \ - | jq -r --arg package_name "$package_name" '.packages[] | select(.name == $package_name) | .manifest_path' \ - | head -n 1 - )" - - if [[ -z "$manifest_path" || "$manifest_path" == "null" ]]; then - echo "Could not determine package directory for $package_name" >&2 - return 1 - fi - - dirname "$manifest_path" -} - -function update_release_notes() { - local package_dir="$1" - local version="$2" - local tag="$3" - local changelog_file="${package_dir}/CHANGELOG.md" - - if [[ ! -f "$changelog_file" ]]; then - echo "Skipping ${tag}: no ${changelog_file}" - return 0 - fi - - echo "Updating ${tag} using ${changelog_file}" - - local notes - notes="$( - awk -v version="$version" ' - $0 == "## " version { - in_section = 1 - next - } - - in_section && /^## / { - exit - } - - in_section { - lines[++count] = $0 - } - - END { - first = 1 - while (first <= count && lines[first] ~ /^[[:space:]]*$/) { - first++ - } - - last = count - while (last >= first && lines[last] ~ /^[[:space:]]*$/) { - last-- - } - - for (i = first; i <= last; i++) { - print lines[i] - } - } - ' "$changelog_file" - )" - - if [[ -z "${notes//[[:space:]]/}" ]]; then - notes="- No significant changes since the previous release." - fi - - gh release edit "$tag" --notes="$notes" -} - -RELEASE_PLZ_RELEASES_JSON="$1" - -specs="$(echo "$RELEASE_PLZ_RELEASES_JSON" | jq -r '.[] | "\(.package_name):\(.version):\(.tag)"')" - -for spec in $specs; do - name="$(echo "$spec" | cut -d: -f1)" - version="$(echo "$spec" | cut -d: -f2)" - tag="$(echo "$spec" | cut -d: -f3)" - package_dir="$(package_dir_for "$name")" - - update_release_notes "$package_dir" "$version" "$tag" -done