|
| 1 | +# Templates |
| 2 | + |
| 3 | +This directory contains template files that can be expanded and copied over to the configured repositories. |
| 4 | + |
| 5 | +## Header |
| 6 | + |
| 7 | +The [header](header.yml) is prepended to all the files before they are copied to the target repositories. |
| 8 | + |
| 9 | +## Contexts |
| 10 | + |
| 11 | +You can access context information during template expansion (before copy is performed). |
| 12 | + |
| 13 | +### About contexts |
| 14 | + |
| 15 | +Contexts are a way to access information about the repository configuration object and repository GitHub settings. Contexts use the following syntax: |
| 16 | + |
| 17 | +``` |
| 18 | +${{{ <context> }}} |
| 19 | +``` |
| 20 | + |
| 21 | +| Context name | Type | Description | |
| 22 | +| --- | --- | --- | |
| 23 | +| `config` | `object` | Configuration object because of which the file is being copied. For more information, see [config context](#config-context) | |
| 24 | +| `github` | `object` | Information about the target repository the file is being copied to. For more information, see [github context](#github-context) | |
| 25 | + |
| 26 | +The context container is generated automatically before template expansion is performed. |
| 27 | + |
| 28 | +#### `config` context |
| 29 | + |
| 30 | +The `config` context is the configuration object because of which the file is being copied. It is created by merging the `defaults` object with a `repository` object (from the `repositories` array) from a JSON configuration file. |
| 31 | + |
| 32 | +| Property name | Type | Always present | Description | |
| 33 | +| --- | --- | --- | --- | |
| 34 | +| `config` | `object` | `true` | The top-level context. | true | |
| 35 | +| `config.files` | `array` | `true` | The files that are being copied. | |
| 36 | +| `config.extra_files` | `array` | `false` | The additional files that are also being copied. | |
| 37 | +| `config.target` | `string` | `true` | The name of the target repository in `{owner}/{repo}` format. | |
| 38 | +| `config.deploy_go` | `boolean` | `false` | Flag controling if Go specific setup should be applied to the repository. | |
| 39 | +| `config.deploy_versioning` | `boolean` | `false` | Flag controling if `versions.json` file should be deployed to the repository. | |
| 40 | +| `config.dist` | `string` | `false` | The name of the distribution built from the repository. | |
| 41 | + |
| 42 | +#### `github` context |
| 43 | + |
| 44 | +The `github` context contains information about the target repository the file is being copied to. It is created on the fly before template expansion is performed. |
| 45 | + |
| 46 | +| Property name | Type | Always present | Description | |
| 47 | +| --- | --- | --- | --- | |
| 48 | +| `github` | `object` | `true` | The top-level context. | |
| 49 | +| `github.default_branch` | `string` | `true` | The name of the default branch of the target repository. | |
| 50 | + |
| 51 | +### Examples |
| 52 | + |
| 53 | +#### JSON configuration |
| 54 | + |
| 55 | +```json |
| 56 | +{ |
| 57 | + "defaults": { |
| 58 | + "files": [".github/workflows/automerge.yml"], |
| 59 | + "is_example": false |
| 60 | + }, |
| 61 | + "repositories": [ |
| 62 | + { |
| 63 | + "target": "protocol/.github-test-target", |
| 64 | + "extra_files": [".github/workflows/example.yml"], |
| 65 | + "example": { |
| 66 | + "greeting": "Hello" |
| 67 | + }, |
| 68 | + "is_example": true |
| 69 | + } |
| 70 | + ] |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +#### Context container |
| 75 | + |
| 76 | +*created automatically before template expansion is performed* |
| 77 | + |
| 78 | +```json |
| 79 | +{ |
| 80 | + "config": { |
| 81 | + "target": "protocol/.github-test-target", |
| 82 | + "files": [".github/workflows/automerge.yml"], |
| 83 | + "extra_files": [".github/workflows/example.yml"], |
| 84 | + "example": { |
| 85 | + "greeting": "Hello" |
| 86 | + }, |
| 87 | + "is_example": true |
| 88 | + }, |
| 89 | + "github": { |
| 90 | + "default_branch": "master" |
| 91 | + } |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | +#### Template |
| 96 | + |
| 97 | +```yaml |
| 98 | +name: Hello |
| 99 | +on: |
| 100 | + push: |
| 101 | + branches: |
| 102 | + - ${{{ github.default_branch }}} |
| 103 | +jobs: |
| 104 | + echo: |
| 105 | + runs-on: ubuntu-latest |
| 106 | + steps: |
| 107 | + - run: echo ${{{ config.example.greeting }}} |
| 108 | + shell: bash |
| 109 | +``` |
| 110 | +
|
| 111 | +#### Expanded template |
| 112 | +
|
| 113 | +```yaml |
| 114 | +name: Hello |
| 115 | +on: |
| 116 | + push: |
| 117 | + branches: |
| 118 | + - master |
| 119 | +jobs: |
| 120 | + echo: |
| 121 | + runs-on: ubuntu-latest |
| 122 | + steps: |
| 123 | + - run: echo Hello |
| 124 | + shell: bash |
| 125 | +``` |
0 commit comments