|
| 1 | +name: Dev Release |
| 2 | + |
| 3 | +# Create incremental pre-release builds on every push to main between stable |
| 4 | +# releases. Computes a PEP 440 dev version (e.g. v0.4.7.dev3) and creates a |
| 5 | +# lightweight git tag + GitHub pre-release. The tag triggers the existing |
| 6 | +# Docker and CLI workflows for full build/scan/sign pipeline. |
| 7 | + |
| 8 | +on: |
| 9 | + push: |
| 10 | + branches: [main] |
| 11 | + |
| 12 | +permissions: {} |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: dev-release |
| 16 | + cancel-in-progress: true |
| 17 | + |
| 18 | +jobs: |
| 19 | + dev-release: |
| 20 | + name: Create Dev Pre-Release |
| 21 | + # Skip Release Please version-bump merges and tag pushes (handled by |
| 22 | + # the stable release pipeline). Also skip if a v* tag already points |
| 23 | + # at this commit (the stable release just landed). |
| 24 | + if: >- |
| 25 | + !startsWith(github.event.head_commit.message, 'chore(main): release') |
| 26 | + && !contains(github.event.head_commit.message, 'Release-As:') |
| 27 | + runs-on: ubuntu-latest |
| 28 | + timeout-minutes: 5 |
| 29 | + permissions: |
| 30 | + contents: write |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 33 | + with: |
| 34 | + fetch-depth: 0 |
| 35 | + persist-credentials: false |
| 36 | + |
| 37 | + - name: Check if commit already has a stable tag |
| 38 | + id: check-tag |
| 39 | + run: | |
| 40 | + # If this commit already has a v* tag (without .dev), skip -- it is |
| 41 | + # a stable release and will be handled by Release Please. |
| 42 | + TAGS=$(git tag --points-at HEAD | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' || true) |
| 43 | + if [ -n "$TAGS" ]; then |
| 44 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 45 | + echo "Commit already tagged as stable release: $TAGS" |
| 46 | + else |
| 47 | + echo "skip=false" >> "$GITHUB_OUTPUT" |
| 48 | + fi |
| 49 | +
|
| 50 | + - name: Compute dev version |
| 51 | + if: steps.check-tag.outputs.skip != 'true' |
| 52 | + id: version |
| 53 | + env: |
| 54 | + GH_TOKEN: ${{ github.token }} |
| 55 | + run: | |
| 56 | + # 1. Find last stable release tag (exclude dev tags) |
| 57 | + LAST_TAG=$(git tag --sort=-v:refname --list "v[0-9]*.[0-9]*.[0-9]*" | grep -vE '\.dev[0-9]+$' | head -1) |
| 58 | + LAST_TAG=${LAST_TAG:-""} |
| 59 | + if [ -z "$LAST_TAG" ]; then |
| 60 | + echo "::error::No stable release tag found" |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | + echo "Last stable tag: $LAST_TAG" |
| 64 | +
|
| 65 | + # 2. Get next version from Release Please pending PR |
| 66 | + NEXT_VERSION=$(gh pr list --label "autorelease: pending" --state open --json title --jq '.[0].title // ""' | grep -oP '\d+\.\d+\.\d+' || true) |
| 67 | + if [ -z "$NEXT_VERSION" ]; then |
| 68 | + # Fallback: bump patch from last tag |
| 69 | + LAST_VERSION="${LAST_TAG#v}" |
| 70 | + IFS='.' read -r MAJOR MINOR PATCH <<< "$LAST_VERSION" |
| 71 | + NEXT_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))" |
| 72 | + echo "No Release Please PR found, computed next version: $NEXT_VERSION" |
| 73 | + else |
| 74 | + echo "Next version from Release Please: $NEXT_VERSION" |
| 75 | + fi |
| 76 | +
|
| 77 | + # 3. Count commits since last stable tag |
| 78 | + DEV_NUM=$(git rev-list "${LAST_TAG}..HEAD" --count) |
| 79 | + if [ "$DEV_NUM" -eq 0 ]; then |
| 80 | + echo "::notice::No commits since $LAST_TAG, skipping dev release" |
| 81 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 82 | + exit 0 |
| 83 | + fi |
| 84 | +
|
| 85 | + DEV_TAG="v${NEXT_VERSION}.dev${DEV_NUM}" |
| 86 | + echo "Dev version: $DEV_TAG" |
| 87 | + echo "dev_tag=$DEV_TAG" >> "$GITHUB_OUTPUT" |
| 88 | + echo "dev_num=$DEV_NUM" >> "$GITHUB_OUTPUT" |
| 89 | + echo "next_version=$NEXT_VERSION" >> "$GITHUB_OUTPUT" |
| 90 | + echo "skip=false" >> "$GITHUB_OUTPUT" |
| 91 | +
|
| 92 | + - name: Check if dev tag already exists |
| 93 | + if: steps.check-tag.outputs.skip != 'true' && steps.version.outputs.skip != 'true' |
| 94 | + id: tag-exists |
| 95 | + env: |
| 96 | + DEV_TAG: ${{ steps.version.outputs.dev_tag }} |
| 97 | + run: | |
| 98 | + if git rev-parse "$DEV_TAG" >/dev/null 2>&1; then |
| 99 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 100 | + echo "Tag $DEV_TAG already exists, skipping" |
| 101 | + else |
| 102 | + echo "skip=false" >> "$GITHUB_OUTPUT" |
| 103 | + fi |
| 104 | +
|
| 105 | + - name: Create dev tag and pre-release |
| 106 | + if: >- |
| 107 | + steps.check-tag.outputs.skip != 'true' |
| 108 | + && steps.version.outputs.skip != 'true' |
| 109 | + && steps.tag-exists.outputs.skip != 'true' |
| 110 | + env: |
| 111 | + GH_TOKEN: ${{ github.token }} |
| 112 | + DEV_TAG: ${{ steps.version.outputs.dev_tag }} |
| 113 | + DEV_NUM: ${{ steps.version.outputs.dev_num }} |
| 114 | + NEXT_VERSION: ${{ steps.version.outputs.next_version }} |
| 115 | + run: | |
| 116 | + SHORT_SHA="${GITHUB_SHA::7}" |
| 117 | +
|
| 118 | + # Create tag + pre-release atomically (gh release create --target |
| 119 | + # creates the tag if it does not exist, avoiding orphaned tags on |
| 120 | + # partial failure). |
| 121 | + gh release create "$DEV_TAG" \ |
| 122 | + --target "$GITHUB_SHA" \ |
| 123 | + --prerelease \ |
| 124 | + --title "$DEV_TAG" \ |
| 125 | + --notes "Dev build #${DEV_NUM} toward v${NEXT_VERSION} |
| 126 | +
|
| 127 | + **Commit:** ${SHORT_SHA} |
| 128 | + **Full pipeline:** Docker images, CLI binaries, cosign signatures, and SLSA provenance will be attached by downstream workflows. |
| 129 | +
|
| 130 | + > This is a pre-release for testing. Use \`synthorg config set channel dev\` to opt in." |
| 131 | +
|
| 132 | + - name: Clean up old dev pre-releases |
| 133 | + if: >- |
| 134 | + steps.check-tag.outputs.skip != 'true' |
| 135 | + && steps.version.outputs.skip != 'true' |
| 136 | + && steps.tag-exists.outputs.skip != 'true' |
| 137 | + env: |
| 138 | + GH_TOKEN: ${{ github.token }} |
| 139 | + run: | |
| 140 | + # Keep the 5 most recent dev pre-releases, delete the rest |
| 141 | + gh release list --limit 50 --json tagName,isPrerelease,createdAt \ |
| 142 | + --jq '[.[] | select(.isPrerelease and (.tagName | contains(".dev")))] | sort_by(.createdAt) | reverse | .[5:] | .[].tagName' \ |
| 143 | + | while read -r tag; do |
| 144 | + echo "Deleting old dev release: $tag" |
| 145 | + gh release delete "$tag" --yes --cleanup-tag 2>/dev/null || true |
| 146 | + done |
0 commit comments