mirror of
https://github.com/matifali/update-coder-template.git
synced 2025-10-27 15:25:55 +08:00
Update docs for v3
This commit is contained in:
parent
4120c03efe
commit
ac7296f2e0
2 changed files with 37 additions and 26 deletions
57
README.md
57
README.md
|
|
@ -5,22 +5,30 @@ Update coder templates automatically
|
|||
## Usage
|
||||
|
||||
1. Create a GitHub secret named `CODER_SESSION_TOKEN` with your coder session token
|
||||
You can generate a long lived session token by running the following command in your browser console while logged into Coder with a **Template Admin** or **Owner** role.
|
||||
|
||||
```shell
|
||||
coder token create --lifetime 8760h --name "GitHub Actions"
|
||||
```
|
||||
|
||||
2. Create a `.github/workflows/push-coder-template.yaml` file and use one of the examples below.
|
||||
|
||||
## Inputs
|
||||
|
||||
| Name | Description | Default |
|
||||
| ------------------------- | ------------------------------------------------------------------------ | ----------------------------- |
|
||||
| `CODER_URL` | **Required** The url of coder deployment (e.g. <https://dev.coder.com>). | - |
|
||||
| `CODER_SESSION_TOKEN` | **Required** The session token of coder. | `secrets.CODER_SESSION_TOKEN` |
|
||||
| `CODER_TEMPLATE_NAME` | **Required** The name of template. | - |
|
||||
| `CODER_TEMPLATE_DIR` | The directory of the template. | `CODER_TEMPLATE_NAME` |
|
||||
| `CODER_TEMPLATE_VERSION` | The version name of the template. | Autogenerated name by Coder |
|
||||
| `CODER_TEMPLATE_ACTIVATE` | Activate the new template version. | `true` |
|
||||
| Name | Description | Default |
|
||||
| ------------------------- | ------------------------------------------------------------------------ | --------------------------- |
|
||||
| **`url`** | **Required** The url of coder deployment (e.g. <https://dev.coder.com>). | - |
|
||||
| **`coder_session_token`** | **Required** The session token of coder. | - |
|
||||
| **`id`** | **Required** The id of template. | - |
|
||||
| **`dir`** | **Required** The directory of the template that contains `main.tf` file | - |
|
||||
| `name` | New version name for the template. | Autogenerated name by Coder |
|
||||
| `activate` | Activate the new template version. | `true` |
|
||||
| `create` | Creates a new template if it does not exist | `true` |
|
||||
| `message` | Update message (similar to commit messages) | - |
|
||||
|
||||
## Examples
|
||||
|
||||
1. Update a Coder template with the latest commit hash as version name and set it as active.
|
||||
1. Update a Coder template with the latest commit hash as the version name, commit message as the update message and mark this as active.
|
||||
|
||||
```yaml
|
||||
name: Update Coder Template
|
||||
|
|
@ -38,16 +46,21 @@ Update coder templates automatically
|
|||
uses: actions/checkout@v3
|
||||
- name: Get latest commit hash
|
||||
id: latest_commit
|
||||
run: echo "::set-output name=hash::$(git rev-parse --short HEAD)"
|
||||
run: echo "hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
|
||||
- name: Get commit title
|
||||
id: commit_title
|
||||
run: echo "title=$(git log -1 --pretty=%B)" >> $GITHUB_OUTPUT
|
||||
|
||||
|
||||
- name: Update Coder Template
|
||||
uses: matifali/update-coder-template@v2
|
||||
uses: matifali/update-coder-template@v3
|
||||
with:
|
||||
CODER_TEMPLATE_NAME: "my-template"
|
||||
CODER_TEMPLATE_DIR: "my-template"
|
||||
CODER_URL: "https://coder.example.com"
|
||||
CODER_TEMPLATE_VERSION: "${{ steps.latest_commit.outputs.hash }}"
|
||||
CODER_SESSION_TOKEN: ${{ secrets.CODER_SESSION_TOKEN }}
|
||||
id: "my-template"
|
||||
dir: "my-template"
|
||||
url: "https://coder.example.com"
|
||||
name: "${{ steps.latest_commit.outputs.hash }}"
|
||||
message: "${{ steps.commit_title.outputs.title }}"
|
||||
coder_session_token: ${{ secrets.CODER_SESSION_TOKEN }}
|
||||
```
|
||||
|
||||
2. Update a Coder template with a random version name without activating.
|
||||
|
|
@ -68,11 +81,11 @@ Update coder templates automatically
|
|||
uses: actions/checkout@v3
|
||||
|
||||
- name: Update Coder Template
|
||||
uses: matifali/update-coder-template@v2
|
||||
uses: matifali/update-coder-template@v3
|
||||
with:
|
||||
CODER_TEMPLATE_NAME: "my-template"
|
||||
CODER_TEMPLATE_DIR: "my-template"
|
||||
CODER_URL: "https://coder.example.com"
|
||||
CODER_TEMPLATE_ACTIVATE: "false"
|
||||
CODER_SESSION_TOKEN: ${{ secrets.CODER_SESSION_TOKEN }}
|
||||
id: "my-template"
|
||||
dir: "my-template"
|
||||
url: "https://coder.example.com"
|
||||
activate: "false"
|
||||
coder_session_token: ${{ secrets.CODER_SESSION_TOKEN }}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -8,10 +8,8 @@ echo "CODER_SESSION_TOKEN is set."
|
|||
echo "CODER_URL is set."
|
||||
: "${CODER_TEMPLATE_ID:?CODER_TEMPLATE_ID not set or empty}"
|
||||
echo "CODER_TEMPLATE_ID: ${CODER_TEMPLATE_ID}"
|
||||
|
||||
# Set default values if variables are empty
|
||||
CODER_TEMPLATE_DIR=${CODER_TEMPLATE_DIR:-$CODER_TEMPLATE_ID}
|
||||
echo "CODER_TEMPLATE_DIR is set to ${CODER_TEMPLATE_DIR}"
|
||||
: "${CODER_TEMPLATE_DIR:?CODER_TEMPLATE_DIR not set or empty}"
|
||||
echo "CODER_TEMPLATE_DIR: ${CODER_TEMPLATE_DIR}"
|
||||
|
||||
# Construct push command
|
||||
push_command="coder templates push ${CODER_TEMPLATE_NAME} --directory ./${CODER_TEMPLATE_DIR}" --message ${CODER_TEMPLATE_MESSAGE}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue