|
| 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 | + environment: release |
| 30 | + permissions: |
| 31 | + contents: write |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 34 | + with: |
| 35 | + fetch-depth: 0 |
| 36 | + persist-credentials: false |
| 37 | + |
| 38 | + - name: Check if commit already has a stable tag |
| 39 | + id: check-tag |
| 40 | + run: | |
| 41 | + # If this commit already has a v* tag (without .dev), skip -- it is |
| 42 | + # a stable release and will be handled by Release Please. |
| 43 | + TAGS=$(git tag --points-at HEAD | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' || true) |
| 44 | + if [ -n "$TAGS" ]; then |
| 45 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 46 | + echo "Commit already tagged as stable release: $TAGS" |
| 47 | + else |
| 48 | + echo "skip=false" >> "$GITHUB_OUTPUT" |
| 49 | + fi |
| 50 | +
|
| 51 | + - name: Compute dev version |
| 52 | + if: steps.check-tag.outputs.skip != 'true' |
| 53 | + id: version |
| 54 | + env: |
| 55 | + GH_TOKEN: ${{ github.token }} |
| 56 | + run: | |
| 57 | + # 1. Find last stable release tag (exclude dev tags) |
| 58 | + LAST_TAG=$(git tag --sort=-v:refname --list "v[0-9]*.[0-9]*.[0-9]*" | grep -vE '\.dev[0-9]+$' | head -1) |
| 59 | + LAST_TAG=${LAST_TAG:-""} |
| 60 | + if [ -z "$LAST_TAG" ]; then |
| 61 | + echo "::error::No stable release tag found" |
| 62 | + exit 1 |
| 63 | + fi |
| 64 | + echo "Last stable tag: $LAST_TAG" |
| 65 | +
|
| 66 | + # 2. Get next version from Release Please pending PR |
| 67 | + NEXT_VERSION=$(gh pr list --label "autorelease: pending" --state open --json title --jq '.[0].title // ""' | grep -oP '\d+\.\d+\.\d+' || true) |
| 68 | + if [ -z "$NEXT_VERSION" ]; then |
| 69 | + # Fallback: bump patch from last tag |
| 70 | + LAST_VERSION="${LAST_TAG#v}" |
| 71 | + IFS='.' read -r MAJOR MINOR PATCH <<< "$LAST_VERSION" |
| 72 | + NEXT_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))" |
| 73 | + echo "No Release Please PR found, computed next version: $NEXT_VERSION" |
| 74 | + else |
| 75 | + echo "Next version from Release Please: $NEXT_VERSION" |
| 76 | + fi |
| 77 | +
|
| 78 | + # 3. Count commits since last stable tag |
| 79 | + DEV_NUM=$(git rev-list "${LAST_TAG}..HEAD" --count) |
| 80 | + if [ "$DEV_NUM" -eq 0 ]; then |
| 81 | + echo "::notice::No commits since $LAST_TAG, skipping dev release" |
| 82 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 83 | + exit 0 |
| 84 | + fi |
| 85 | +
|
| 86 | + DEV_TAG="v${NEXT_VERSION}.dev${DEV_NUM}" |
| 87 | + echo "Dev version: $DEV_TAG" |
| 88 | + echo "dev_tag=$DEV_TAG" >> "$GITHUB_OUTPUT" |
| 89 | + echo "dev_num=$DEV_NUM" >> "$GITHUB_OUTPUT" |
| 90 | + echo "next_version=$NEXT_VERSION" >> "$GITHUB_OUTPUT" |
| 91 | + echo "skip=false" >> "$GITHUB_OUTPUT" |
| 92 | +
|
| 93 | + - name: Check if dev tag already exists |
| 94 | + if: steps.check-tag.outputs.skip != 'true' && steps.version.outputs.skip != 'true' |
| 95 | + id: tag-exists |
| 96 | + env: |
| 97 | + DEV_TAG: ${{ steps.version.outputs.dev_tag }} |
| 98 | + run: | |
| 99 | + if git rev-parse "$DEV_TAG" >/dev/null 2>&1; then |
| 100 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 101 | + echo "Tag $DEV_TAG already exists, skipping" |
| 102 | + else |
| 103 | + echo "skip=false" >> "$GITHUB_OUTPUT" |
| 104 | + fi |
| 105 | +
|
| 106 | + - name: Create dev tag and pre-release |
| 107 | + if: >- |
| 108 | + steps.check-tag.outputs.skip != 'true' |
| 109 | + && steps.version.outputs.skip != 'true' |
| 110 | + && steps.tag-exists.outputs.skip != 'true' |
| 111 | + env: |
| 112 | + # Use PAT instead of github.token so the tag push triggers |
| 113 | + # downstream workflows (Docker, CLI). Tags created with the |
| 114 | + # default GITHUB_TOKEN do not fire push events for other |
| 115 | + # workflows -- a GitHub Actions anti-recursion safeguard. |
| 116 | + GH_TOKEN: ${{ secrets.RELEASE_PLEASE_TOKEN }} |
| 117 | + DEV_TAG: ${{ steps.version.outputs.dev_tag }} |
| 118 | + DEV_NUM: ${{ steps.version.outputs.dev_num }} |
| 119 | + NEXT_VERSION: ${{ steps.version.outputs.next_version }} |
| 120 | + run: | |
| 121 | + SHORT_SHA="${GITHUB_SHA::7}" |
| 122 | +
|
| 123 | + # Create tag + pre-release atomically (gh release create --target |
| 124 | + # creates the tag if it does not exist, avoiding orphaned tags on |
| 125 | + # partial failure). |
| 126 | + gh release create "$DEV_TAG" \ |
| 127 | + --target "$GITHUB_SHA" \ |
| 128 | + --prerelease \ |
| 129 | + --title "$DEV_TAG" \ |
| 130 | + --notes "Dev build #${DEV_NUM} toward v${NEXT_VERSION} |
| 131 | +
|
| 132 | + **Commit:** ${SHORT_SHA} |
| 133 | + **Full pipeline:** Docker images, CLI binaries, cosign signatures, and SLSA provenance will be attached by downstream workflows. |
| 134 | +
|
| 135 | + > This is a pre-release for testing. Use \`synthorg config set channel dev\` to opt in." |
| 136 | +
|
| 137 | + - name: Clean up old dev pre-releases |
| 138 | + if: >- |
| 139 | + steps.check-tag.outputs.skip != 'true' |
| 140 | + && steps.version.outputs.skip != 'true' |
| 141 | + && steps.tag-exists.outputs.skip != 'true' |
| 142 | + env: |
| 143 | + GH_TOKEN: ${{ github.token }} |
| 144 | + run: | |
| 145 | + # Keep the 5 most recent dev pre-releases, delete the rest |
| 146 | + gh release list --limit 50 --json tagName,isPrerelease,createdAt \ |
| 147 | + --jq '[.[] | select(.isPrerelease and (.tagName | contains(".dev")))] | sort_by(.createdAt) | reverse | .[5:] | .[].tagName' \ |
| 148 | + | while read -r tag; do |
| 149 | + echo "Deleting old dev release: $tag" |
| 150 | + gh release delete "$tag" --yes --cleanup-tag 2>/dev/null || true |
| 151 | + done |
0 commit comments