|
| 1 | +# Linear Release — CircleCI (Scheduled) |
| 2 | +# |
| 3 | +# Use when: Releases follow a branch cut model. Main syncs without a version, |
| 4 | +# release branches derive version from CIRCLE_BRANCH. |
| 5 | +# |
| 6 | +# Trigger: Auto on push, API trigger for later stage transitions and completion. |
| 7 | +# Customize: Branch patterns, stage names, auto-promotion stage. |
| 8 | +# Note: Set LINEAR_ACCESS_KEY and CIRCLE_TOKEN in CircleCI project settings. |
| 9 | +# |
| 10 | +# Branch creation detection: CircleCI has no built-in signal, so auto-promotion |
| 11 | +# checks the API for previous pipelines on the branch. |
| 12 | +# |
| 13 | +# Monorepo: CircleCI doesn't support path filtering natively. Use the `path-filtering` |
| 14 | +# orb or split into separate workflows and use the API to conditionally trigger. |
| 15 | + |
| 16 | +version: 2.1 |
| 17 | + |
| 18 | +# Pipeline parameters — passed via CircleCI API for manual stage transitions. |
| 19 | +# On normal pushes, defaults apply and only the sync workflows run. |
| 20 | +parameters: |
| 21 | + run-release-action: |
| 22 | + type: boolean |
| 23 | + default: false |
| 24 | + action: |
| 25 | + type: enum |
| 26 | + enum: ["update", "complete"] |
| 27 | + default: "update" |
| 28 | + stage: |
| 29 | + type: string |
| 30 | + default: "" |
| 31 | + release_version: |
| 32 | + type: string |
| 33 | + default: "" |
| 34 | + |
| 35 | +jobs: |
| 36 | + linear-release-sync-main: |
| 37 | + docker: |
| 38 | + - image: cimg/base:current |
| 39 | + steps: |
| 40 | + - checkout |
| 41 | + - run: |
| 42 | + name: Download Linear Release |
| 43 | + command: | |
| 44 | + curl -sL https://github.com/linear/linear-release/releases/latest/download/linear-release-linux-x64 -o linear-release |
| 45 | + chmod +x linear-release |
| 46 | + - run: |
| 47 | + name: Sync release |
| 48 | + command: ./linear-release sync |
| 49 | + |
| 50 | + linear-release-sync-release: |
| 51 | + docker: |
| 52 | + - image: cimg/base:current |
| 53 | + steps: |
| 54 | + - checkout |
| 55 | + - run: |
| 56 | + name: Download Linear Release |
| 57 | + command: | |
| 58 | + curl -sL https://github.com/linear/linear-release/releases/latest/download/linear-release-linux-x64 -o linear-release |
| 59 | + chmod +x linear-release |
| 60 | + - run: |
| 61 | + name: Derive version and sync |
| 62 | + command: | |
| 63 | + RELEASE_VERSION="${CIRCLE_BRANCH#release/}" |
| 64 | + ./linear-release sync --release-version="$RELEASE_VERSION" |
| 65 | + - run: |
| 66 | + name: Auto-promote on branch creation |
| 67 | + command: | |
| 68 | + RELEASE_VERSION="${CIRCLE_BRANCH#release/}" |
| 69 | + # Check if this is the first pipeline on this branch (branch creation) |
| 70 | + PIPELINE_COUNT=$(curl -s -H "Circle-Token: $CIRCLE_TOKEN" \ |
| 71 | + "https://circleci.com/api/v2/project/gh/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/pipeline?branch=$CIRCLE_BRANCH" \ |
| 72 | + | jq '.items | length') |
| 73 | + if [ "$PIPELINE_COUNT" -le 1 ]; then |
| 74 | + ./linear-release update --release-version="$RELEASE_VERSION" --stage="code freeze" |
| 75 | + fi |
| 76 | +
|
| 77 | + linear-release-action: |
| 78 | + docker: |
| 79 | + - image: cimg/base:current |
| 80 | + steps: |
| 81 | + - checkout |
| 82 | + - run: |
| 83 | + name: Download Linear Release |
| 84 | + command: | |
| 85 | + curl -sL https://github.com/linear/linear-release/releases/latest/download/linear-release-linux-x64 -o linear-release |
| 86 | + chmod +x linear-release |
| 87 | + - run: |
| 88 | + name: Run release action |
| 89 | + command: | |
| 90 | + case "<< pipeline.parameters.action >>" in |
| 91 | + update) |
| 92 | + ./linear-release update \ |
| 93 | + --release-version="<< pipeline.parameters.release_version >>" \ |
| 94 | + --stage="<< pipeline.parameters.stage >>" |
| 95 | + ;; |
| 96 | + complete) |
| 97 | + ./linear-release complete \ |
| 98 | + --release-version="<< pipeline.parameters.release_version >>" |
| 99 | + ;; |
| 100 | + esac |
| 101 | +
|
| 102 | +workflows: |
| 103 | + # On normal pushes — sync issues to the release |
| 104 | + release-sync-main: |
| 105 | + when: |
| 106 | + not: << pipeline.parameters.run-release-action >> |
| 107 | + jobs: |
| 108 | + - linear-release-sync-main: |
| 109 | + filters: |
| 110 | + branches: |
| 111 | + only: main |
| 112 | + |
| 113 | + release-sync-release: |
| 114 | + when: |
| 115 | + not: << pipeline.parameters.run-release-action >> |
| 116 | + jobs: |
| 117 | + - linear-release-sync-release: |
| 118 | + filters: |
| 119 | + branches: |
| 120 | + only: /^release\/.*/ |
| 121 | + |
| 122 | + # Trigger via CircleCI API: |
| 123 | + # curl -X POST https://circleci.com/api/v2/project/gh/ORG/REPO/pipeline \ |
| 124 | + # -H "Circle-Token: $CIRCLE_TOKEN" -H "Content-Type: application/json" \ |
| 125 | + # -d '{"parameters": {"run-release-action": true, "action": "update", "stage": "qa", "release_version": "1.2.0"}}' |
| 126 | + release-action: |
| 127 | + when: << pipeline.parameters.run-release-action >> |
| 128 | + jobs: |
| 129 | + - linear-release-action |
0 commit comments