Skip to content

Commit

Permalink
Don’t do most CD steps for v < 2
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Jan 17, 2025
1 parent e5b86d8 commit 3450e3b
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 61 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: 19 additions & 18 deletions .github/workflows/cd.docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ jobs:
tag: ${{ github.event.inputs.tag }}
fileName: pkgx-*.tar.xz

- name: determine if we are latest
id: tags
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
TAGS="$TAGS type=raw,value=latest"
fi
echo "value=$TAGS" >> $GITHUB_OUTPUT
env:
TAGS: >
type=sha
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 }}
- name: Unpack Binaries
run: |
for filename in pkgx-*+*+*.tar.xz; do
Expand All @@ -47,13 +63,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 +72,8 @@ jobs:
- uses: docker/metadata-action@v5
id: meta
with:
images:
ghcr.io/${{ github.repository }}
pkgxdev/pkgx
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
images: pkgxdev/pkgx
tags: ${{ steps.tags.outputs.value }}

- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
Expand All @@ -87,4 +88,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
3 changes: 0 additions & 3 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,3 @@ rusqlite = { version = "0.32.1", features = ["bundled"] }
native-tls = { version = "0.2", features = ["vendored"] }
# ^^ this is a transitive dependency
# ^^ we vendor OpenSSL ∵ we want to be standalone and just work inside minimal docker images

[profile.release]
lto = "fat"
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 3450e3b

Please sign in to comment.