|
| 1 | +name: Push Coder Template |
| 2 | + |
| 3 | +# Push a new template version to the Coder instance on: |
| 4 | +# 1. Master changes to main.tf or this workflow file (template-only edits |
| 5 | +# that don't trigger an image rebuild). |
| 6 | +# 2. Successful completion of "Publish Workspace Images" — so the new |
| 7 | +# image digest baked in by data.docker_registry_image gets a fresh |
| 8 | +# template version pinned to it. |
| 9 | +# 3. Manual dispatch for one-off pushes (e.g. after editing by hand). |
| 10 | +on: |
| 11 | + push: |
| 12 | + branches: [master] |
| 13 | + paths: |
| 14 | + - "main.tf" |
| 15 | + - ".github/workflows/push-template.yml" |
| 16 | + workflow_run: |
| 17 | + workflows: ["Publish Workspace Images"] |
| 18 | + branches: [master] |
| 19 | + types: [completed] |
| 20 | + workflow_dispatch: |
| 21 | + |
| 22 | +jobs: |
| 23 | + push: |
| 24 | + # workflow_run fires on any conclusion; gate on success. Direct push and |
| 25 | + # manual dispatch always proceed. |
| 26 | + if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }} |
| 27 | + runs-on: ubuntu-24.04 |
| 28 | + env: |
| 29 | + # Template metadata — repo is source of truth, re-applied on every push. |
| 30 | + TEMPLATE_NAME: workspaces |
| 31 | + TEMPLATE_DISPLAY_NAME: SoureCode Workspaces |
| 32 | + TEMPLATE_DESCRIPTION: "Sysbox-backed workspaces with a baked-in dev kit. Stacks: base, node, cpp." |
| 33 | + TEMPLATE_ICON: /emojis/1f9f0.png |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v6 |
| 36 | + with: |
| 37 | + # workflow_run runs against the default-branch SHA implicitly; be |
| 38 | + # explicit so every trigger checks out the same commit the event |
| 39 | + # refers to. |
| 40 | + ref: ${{ github.event.workflow_run.head_sha || github.sha }} |
| 41 | + |
| 42 | + - name: Set up Coder CLI |
| 43 | + uses: coder/setup-action@v1 |
| 44 | + with: |
| 45 | + access_url: ${{ secrets.CODER_URL }} |
| 46 | + coder_session_token: ${{ secrets.CODER_SESSION_TOKEN }} |
| 47 | + |
| 48 | + - name: Stage template archive |
| 49 | + # `coder templates push` tars the --directory and uploads the whole |
| 50 | + # tree. Only main.tf defines the template; staging into a clean dir |
| 51 | + # keeps README, docs/, src/, scripts/, .github/ etc. out of the |
| 52 | + # archive. Deterministic across Coder versions; no reliance on |
| 53 | + # .coderignore / .gitignore interpretation. |
| 54 | + run: | |
| 55 | + set -euo pipefail |
| 56 | + mkdir -p "$RUNNER_TEMP/coder-template" |
| 57 | + cp main.tf "$RUNNER_TEMP/coder-template/" |
| 58 | +
|
| 59 | + - name: Push template version |
| 60 | + run: | |
| 61 | + set -euo pipefail |
| 62 | + version_name="$(git rev-parse --short HEAD)" |
| 63 | + commit_msg="$(git log -1 --format=%B HEAD)" |
| 64 | + coder templates push "$TEMPLATE_NAME" \ |
| 65 | + --directory "$RUNNER_TEMP/coder-template" \ |
| 66 | + --name "$version_name" \ |
| 67 | + --message "$commit_msg" \ |
| 68 | + --yes |
| 69 | +
|
| 70 | + - name: Sync template metadata |
| 71 | + # Template-level fields (display name, description, icon) are managed |
| 72 | + # by `coder templates edit`, not `push`. Running unconditionally keeps |
| 73 | + # the Coder UI in sync with the values declared above. |
| 74 | + run: | |
| 75 | + set -euo pipefail |
| 76 | + coder templates edit "$TEMPLATE_NAME" \ |
| 77 | + --display-name "$TEMPLATE_DISPLAY_NAME" \ |
| 78 | + --description "$TEMPLATE_DESCRIPTION" \ |
| 79 | + --icon "$TEMPLATE_ICON" \ |
| 80 | + --yes |
0 commit comments