Skip to content

Commit

Permalink
Don’t do some CD for 1.x releases
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Jan 17, 2025
1 parent d1834ab commit 8f5343d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 56 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cd.brew.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ concurrency:

jobs:
bump-tap:
if: startsWith(github.event.release.tag_name, 2)
runs-on: ubuntu-latest
steps:
- uses: aurelien-baudet/workflow-dispatch@v4
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/cd.crates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ concurrency:

jobs:
publish:
if: startsWith(github.event.release.tag_name, 2)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
37 changes: 21 additions & 16 deletions .github/workflows/cd.docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ permissions:

jobs:
build-and-push-image:
name: docker buildx pkgxdev/pkgx:${{ github.event.release.tag_name || github.event.inputs.tag }}
runs-on: ubuntu-latest
steps:
- uses: robinraju/release-downloader@v1.11
Expand All @@ -27,6 +28,19 @@ jobs:
tag: ${{ github.event.inputs.tag }}
fileName: pkgx-*.tar.xz

- name: is_latest?
id: latest
run: |
TAG_NAME="${{ github.event.release.tag_name || github.event.inputs.tag }}"
LATEST_RELEASE=$(gh api repos/${{ github.repository }}/releases/latest --jq '.tag_name')
if [ "$TAG_NAME" == "$LATEST_RELEASE" ]; then
echo "value=true" >> "${GITHUB_OUTPUT}"
else
echo "value=false" >> "${GITHUB_OUTPUT}"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Unpack Binaries
run: |
for filename in pkgx-*+*+*.tar.xz; do
Expand All @@ -47,13 +61,6 @@ jobs:
with:
path: src

- name: log in to github pkgs
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: log in to docker hub
uses: docker/login-action@v3
with:
Expand All @@ -63,16 +70,14 @@ jobs:
- uses: docker/metadata-action@v5
id: meta
with:
images:
ghcr.io/${{ github.repository }}
pkgxdev/pkgx
images: pkgxdev/pkgx
flavor: |
latest=${{ steps.latest.outputs.value }}
tags: |
type=sha
type=ref,event=branch
type=semver,pattern=v{{version}}
type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern=v{{major}}
type=raw,value=latest
type=semver,pattern=v{{version}},value=${{ github.event.release.tag_name || github.event.inputs.tag }}
type=semver,pattern=v{{major}}.{{minor}},value=${{ github.event.release.tag_name || github.event.inputs.tag }}
type=semver,pattern=v{{major}},value=${{ github.event.release.tag_name || github.event.inputs.tag }}
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
Expand All @@ -87,4 +92,4 @@ jobs:
$tags \
--platform linux/amd64,linux/arm64 \
--file ./src/.github/Dockerfile \
.
.
1 change: 1 addition & 0 deletions .github/workflows/cd.vx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ jobs:
- run: |
git tag -f latest
git push origin latest --force
if: startsWith(github.event.release.tag_name, 2)
1 change: 1 addition & 0 deletions .github/workflows/cd.www.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ concurrency:

jobs:
www-upload:
if: startsWith(github.event.release.tag_name, 2)
runs-on: ubuntu-latest
steps:
- uses: aws-actions/configure-aws-credentials@v4
Expand Down
52 changes: 12 additions & 40 deletions scripts/publish-release.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#!/usr/bin/env -S pkgx +git +gh +jq +gum +npx +deno bash -eo pipefail

# the back and forth here is because draft releases cannot trigger
# GitHub Actions 😒
#!/usr/bin/env -S pkgx +git +gh +jq +gum bash -eo pipefail

if ! git diff-index --quiet HEAD --; then
echo "error: dirty working tree" >&2
Expand All @@ -13,39 +10,10 @@ if [ "$(git rev-parse --abbrev-ref HEAD)" != main ]; then
exit 1
fi

# ensure we have the latest version tags
git fetch origin -pft

versions="$(git tag | grep '^v[0-9]\+\.[0-9]\+\.[0-9]\+')"
v_latest="$(npx -- semver --include-prerelease $versions | tail -n1)"

_is_prerelease() {
deno run - <<EoTS
import { parse } from "https://deno.land/x/semver/mod.ts";
console.log(parse('$1')?.prerelease.length ? 'true' : 'false');
EoTS
}
v_new=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "pkgx") | .version')

case $1 in
major|minor|patch|prerelease)
v_new=$(npx -- semver bump $v_latest --increment $1)
;;
"")
echo "usage $0 <major|minor|patch|prerelease|VERSION>" >&2
exit 1;;
*)
v_new=$1
;;
esac

if [ $v_new = $v_latest ]; then
echo "$v_new already exists!" >&2
exit 1
fi

is_prerelease=$(_is_prerelease $v_new)

if ! gh release view v$v_new >/dev/null 2>&1; then
case $(gh release view --json isDraft | jq .isDraft) in
'release not found')
gum confirm "prepare draft release for $v_new?" || exit 1

gh release create \
Expand All @@ -56,13 +24,17 @@ if ! gh release view v$v_new >/dev/null 2>&1; then
--notes-start-tag=v$v_latest \
--title=v$v_new

git push origin main
else
;;
true)
gum format "> existing $v_new draft found, using that"
echo #spacer
;;
false)
gum format "$v_new already published! edit \`./crates/cli/Cargo.toml\`"
exit 1;;
esac

git push origin main
fi
git push origin main

gh workflow run cd.yml --raw-field version="$v_new"
# ^^ infuriatingly does not tell us the ID of the run
Expand Down

0 comments on commit 8f5343d

Please sign in to comment.