Skip to content

docs: add guide for CI/CD template testing #15528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update manifest to include testing templates guide
Add a new entry in the documentation's manifest for a tutorial on testing
and publishing Coder templates in a CI/CD pipeline.
  • Loading branch information
matifali committed Nov 15, 2024
commit c3913030bbfc93d141e1a98cf4581699fa35aa0d
5 changes: 5 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,11 @@
"description": "Learn how to clone Git repositories in Coder",
"path": "./tutorials/cloning-git-repositories.md"
},
{
"title": "Testing Templates",
"description": "Learn how to test and publish Coder templates in a CI/CD pipeline",
"path": "./tutorials/testing-templates.md"
},
{
"title": "Use Apache as a Reverse Proxy",
"description": "Learn how to use Apache as a reverse proxy",
Expand Down
21 changes: 11 additions & 10 deletions docs/tutorials/testing-templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Before proceeding, ensure the following:
- **Coder CLI** is installed and configured in your environment.
- **Terraform CLI** is installed and available in your CI environment.
- Access to your **Coder instance** with the appropriate
[permissions](../admin/users/groups-roles#roles).
[permissions](../admin/users/groups-roles.md#roles).

## Example GitHub Action Workflow

Expand All @@ -44,8 +44,8 @@ workspace creation.

### Workflow File

Save the following workflow file as `.github/workflows/template-ci.yaml` in your
repository:
Save the following workflow file as `.github/workflows/publish-template.yaml` in
your repository:

```yaml
name: Test and Publish Coder Template
Expand All @@ -59,8 +59,8 @@ on:
jobs:
test-and-publish:
runs-on: ubuntu-latest
env:
TEMPLATE_NAME: "my-template"
env:
TEMPLATE_NAME: "my-template"
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -73,8 +73,8 @@ jobs:
- name: Set up Coder CLI
uses: coder/setup-action@v1
with:
access_url: 'https://coder.example.com'
coder_session_token: ${{ secrets.CODER_SESSION_TOKEN }}
access_url: "https://coder.example.com"
coder_session_token: ${{ secrets.CODER_SESSION_TOKEN }}

- name: Validate Terraform template
run: terraform validate
Expand All @@ -85,11 +85,13 @@ jobs:

- name: Get latest commit title to use as template version description
id: message
run: echo "pr_title=$(git log --format=%s -n 1 ${{ github.sha }})" >> $GITHUB_OUTPUT
run:
echo "pr_title=$(git log --format=%s -n 1 ${{ github.sha }})" >>
$GITHUB_OUTPUT

- name: Push template to Coder
run: |
coder templates push $TEMPLATE_NAME --activate=false --name ${{ steps.name.outputs.version_name }} --message ${{ steps.message.outputs.pr_title }} --yes
coder templates push $TEMPLATE_NAME --activate=false --name ${{ steps.name.outputs.version_name }} --message "${{ steps.message.outputs.pr_title }}" --yes

- name: Create a test workspace
run: |
Expand All @@ -99,5 +101,4 @@ jobs:
if: success()
run: |
coder template version promote --template=$TEMPLATE_NAME --template-version=${{ steps.name.outputs.version_name }} --yes

```