Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 33 additions & 19 deletions .github/workflows/dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
name: Distribute Binaries

on:
push:
tags: [cargo-changeset@v*]
workflow_dispatch:

permissions:
contents: write
contents: read

concurrency:
group: dist-${{ github.ref }}
cancel-in-progress: false

jobs:
build:
Expand Down Expand Up @@ -56,10 +58,16 @@ jobs:
if: ${{ !matrix.use_cross }}
run: cargo build --release --package cargo-changeset --target ${{ matrix.target }}

- name: Extract version from tag
- name: Determine archive version
id: version
shell: bash
run: echo "version=${GITHUB_REF_NAME#cargo-changeset@v}" >> "$GITHUB_OUTPUT"
run: |
if [[ "$GITHUB_REF" == refs/tags/cargo-changeset@v* ]]; then
version="${GITHUB_REF_NAME#cargo-changeset@v}"
else
version="0.0.0-${GITHUB_SHA::7}"
fi
echo "version=$version" >> "$GITHUB_OUTPUT"

- name: Package binary (Unix)
if: ${{ matrix.archive_ext == 'tar.gz' }}
Expand Down Expand Up @@ -98,27 +106,33 @@ jobs:

release:
name: Create GitHub Release
if: ${{ startsWith(github.ref, 'refs/tags/cargo-changeset@v') }}
runs-on: ubuntu-latest
needs: build
permissions:
contents: write
steps:
- uses: actions/checkout@v6

- name: Extract version from tag
id: version
run: echo "version=${GITHUB_REF_NAME#cargo-changeset@v}" >> "$GITHUB_OUTPUT"

- name: Download all artifacts
uses: actions/download-artifact@v8
with:
pattern: binary-*
merge-multiple: true

- name: Create GitHub Release
run: |
gh release create "$GITHUB_REF_NAME" \
--title "cargo-changeset v${{ steps.version.outputs.version }}" \
--generate-notes \
cargo-changeset-${{ steps.version.outputs.version }}-*.tar.gz \
cargo-changeset-${{ steps.version.outputs.version }}-*.zip
- name: Create or update GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: |-
shopt -s failglob
version="${GITHUB_REF_NAME#cargo-changeset@v}"
assets=(cargo-changeset-"$version"-*.tar.gz cargo-changeset-"$version"-*.zip)
if gh release view "$GITHUB_REF_NAME" > /dev/null 2>&1; then
echo "Release $GITHUB_REF_NAME exists, replacing its assets"
gh release upload "$GITHUB_REF_NAME" --clobber "${assets[@]}"
else
gh release create "$GITHUB_REF_NAME" \
--verify-tag \
--title "cargo-changeset v$version" \
--generate-notes \
"${assets[@]}"
fi
20 changes: 16 additions & 4 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: Publish Docker Image

on:
push:
tags:
- "cargo-changeset@v*"
workflow_dispatch:

env:
Expand Down Expand Up @@ -38,16 +35,18 @@ jobs:
with:
images: |
${{ env.GHCR_IMAGE }}
${{ env.DOCKERHUB_IMAGE }}
name=${{ env.DOCKERHUB_IMAGE }},enable=${{ github.repository == 'lukidoescode/cargo-changeset' }}

- name: Log in to GHCR
if: ${{ github.repository == 'lukidoescode/cargo-changeset' }}
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Log in to Docker Hub
if: ${{ github.repository == 'lukidoescode/cargo-changeset' }}
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
Expand All @@ -57,6 +56,7 @@ jobs:
uses: docker/setup-buildx-action@v4

- name: Build and push by digest
if: ${{ github.repository == 'lukidoescode/cargo-changeset' }}
id: build
uses: docker/build-push-action@v7
with:
Expand All @@ -65,13 +65,24 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,"name=${{ env.GHCR_IMAGE }},${{ env.DOCKERHUB_IMAGE }}",push-by-digest=true,name-canonical=true,push=true

- name: Build without pushing outside the upstream repository
if: ${{ github.repository != 'lukidoescode/cargo-changeset' }}
uses: docker/build-push-action@v7
with:
context: .
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=cacheonly

- name: Export digest
if: ${{ github.repository == 'lukidoescode/cargo-changeset' }}
run: | # zizmor: ignore[template-injection]
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"

- name: Upload digest
if: ${{ github.repository == 'lukidoescode/cargo-changeset' }}
uses: actions/upload-artifact@v7
with:
name: digests-${{ matrix.digest-name }}
Expand All @@ -80,6 +91,7 @@ jobs:
retention-days: 1

merge:
if: ${{ github.repository == 'lukidoescode/cargo-changeset' }}
runs-on: ubuntu-latest
needs: build
environment: docker publish
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/lint-github-workflows-and-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ jobs:
run: ${{ steps.get_actionlint.outputs.executable }} -color # zizmor: ignore[template-injection]
shell: bash

test-dispatch-script:
name: Test release dispatch script
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false

- name: Run dispatch-publish.sh tests
run: bash .github/workflows/scripts/test-dispatch-publish.sh

zizmor:
name: Security audit workflows and actions (zizmor)
runs-on: ubuntu-latest
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
name: Publish Crate

on:
push:
tags: ['*@v*']
workflow_dispatch:

permissions:
Expand All @@ -25,6 +23,7 @@ jobs:
run: echo "name=${GITHUB_REF_NAME%@v*}" >> "$GITHUB_OUTPUT"

- name: Publish with retry
if: ${{ github.repository == 'lukidoescode/cargo-changeset' }}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |-
Expand Down Expand Up @@ -52,3 +51,9 @@ jobs:
sleep "$delay"
attempt=$(( attempt + 1 ))
done

# Packages every workspace crate so that unpublished versions of
# workspace dependencies resolve locally instead of against crates.io.
- name: Publish dry run outside the upstream repository
if: ${{ github.repository != 'lukidoescode/cargo-changeset' }}
run: cargo publish --workspace --dry-run
45 changes: 37 additions & 8 deletions .github/workflows/scripts/dispatch-publish.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
#!/usr/bin/env bash
# Dispatches publish (and for the CLI crate: dist + docker) workflows for each
# tag pointing at HEAD, in workspace dependency order. A 60-second pause is
# inserted between depth tiers so crates.io has time to index each tier before
# Dispatches the publish workflow for each tag pointing at HEAD, in workspace
# dependency order. The cargo-changeset tag additionally dispatches the dist
# (prebuilt binaries) and docker workflows. A 60-second pause is inserted
# between depth tiers so crates.io has time to index each tier before
# dependents are published.
#
# A failed dispatch does not stop the remaining ones. Failures are summarised
# at the end and make the script exit non-zero.
set -euo pipefail

: "${GITHUB_REPOSITORY:?GITHUB_REPOSITORY must be set}"

failures=()

dispatch() {
local workflow=$1
local tag=$2

echo "Dispatching $workflow for $tag"
if ! gh workflow run "$workflow" --repo "$GITHUB_REPOSITORY" --ref "refs/tags/$tag"; then
echo "::error::Failed to dispatch $workflow for $tag"
failures+=("$workflow for $tag")
fi
}

tags=$(git tag --points-at HEAD)

if [ -z "$tags" ]; then
Expand All @@ -30,7 +49,7 @@ for _ in range(len(names)):
if depths[n] <= depths[d]:
depths[n] = depths[d] + 1

for name in sorted(names, key=lambda n: depths[n]):
for name in sorted(names, key=lambda n: (depths[n], n)):
print(depths[name], name)
")

Expand All @@ -46,12 +65,22 @@ while IFS=" " read -r depth crate; do
fi
current_depth=$depth

echo "Dispatching publish for $tag (depth=$depth)"
gh workflow run publish.yml --repo "$GITHUB_REPOSITORY" --ref "refs/tags/$tag"
echo "Processing $tag (depth=$depth)"
dispatch publish.yml "$tag"

if [ "$crate" = "cargo-changeset" ]; then
echo "Dispatching docker for $tag (depth=$depth)"
gh workflow run docker.yml --repo "$GITHUB_REPOSITORY" --ref "refs/tags/$tag"
dispatch dist.yml "$tag"
dispatch docker.yml "$tag"
fi

done <<< "$depth_order"

if [ "${#failures[@]}" -gt 0 ]; then
echo "::error::${#failures[@]} workflow dispatch(es) failed:"
for failure in "${failures[@]}"; do
echo " - $failure"
done
exit 1
fi

echo "All workflow dispatches succeeded."
Loading
Loading