Skip to content

Commit 5bfd17e

Browse files
authored
Merge pull request #65 from roots/support-repo-token-input
Support repo-token input
2 parents 724aa42 + 2c43322 commit 5bfd17e

File tree

9 files changed

+57
-15
lines changed

9 files changed

+57
-15
lines changed

.github/workflows/test.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
ansible-vault-password: fake
2222
auto-init: false
2323
galaxy-install: false
24+
repo-token: ${{ secrets.GITHUB_TOKEN }}
2425
test-with-trellis:
2526
runs-on: ubuntu-latest
2627
steps:
@@ -34,6 +35,7 @@ jobs:
3435
- uses: ./
3536
with:
3637
ansible-vault-password: fake
38+
repo-token: ${{ secrets.GITHUB_TOKEN }}
3739
test-with-trellis-no-galaxy:
3840
runs-on: ubuntu-latest
3941
steps:
@@ -48,6 +50,7 @@ jobs:
4850
with:
4951
ansible-vault-password: fake
5052
galaxy-install: false
53+
repo-token: ${{ secrets.GITHUB_TOKEN }}
5154
test-with-trellis-no-auto-init:
5255
runs-on: ubuntu-latest
5356
steps:
@@ -62,6 +65,7 @@ jobs:
6265
with:
6366
ansible-vault-password: fake
6467
auto-init: false
68+
repo-token: ${{ secrets.GITHUB_TOKEN }}
6569
test-with-trellis-no-cache-virtualenv:
6670
runs-on: ubuntu-latest
6771
steps:
@@ -76,3 +80,19 @@ jobs:
7680
with:
7781
ansible-vault-password: fake
7882
cache-virtualenv: false
83+
repo-token: ${{ secrets.GITHUB_TOKEN }}
84+
test-no-repo-token:
85+
runs-on: ubuntu-latest
86+
steps:
87+
- uses: actions/checkout@v3
88+
with:
89+
fetch-depth: 0
90+
- uses: actions/setup-node@v3
91+
with:
92+
node-version: 16.x
93+
- run: mkdir trellis
94+
- uses: ./
95+
with:
96+
ansible-vault-password: fake
97+
auto-init: false
98+
galaxy-install: false

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ steps:
2020
- uses: roots/setup-trellis-cli@v1
2121
with:
2222
ansible-vault-password: ${{ secrets.ANSIBLE_VAULT_PASSWORD }}
23+
repo-token: ${{ secrets.GITHUB_TOKEN }}
2324
- run: trellis deploy production
2425
```
2526
@@ -46,6 +47,13 @@ gh secret set ANSIBLE_VAULT_PASSWORD -b $(cat trellis/.vault_pass)
4647
Note: this is a required input even if you don't use Ansible Vault. Just set
4748
this to any random placeholder string.
4849

50+
#### `repo-token`
51+
Optionally set the GitHub token for API authorization. Setting this token will avoid any potential API rate limits.
52+
53+
The best option is to set this to the default token secret which GitHub automatically sets: `secrets.GITHUB_TOKEN`.
54+
55+
See https://docs.github.com/en/actions/security-guides/automatic-token-authentication
56+
4957
#### `auto-init`
5058
Whether to automatically run the `trellis init` command after install.
5159

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ inputs:
2020
description: 'Whether to automatically run `trellix galaxy install` (default: true).'
2121
required: false
2222
default: true
23+
repo-token:
24+
description: 'GitHub repository access token used for API authentication. Set this to avoid API rate limits.'
25+
required: false
2326
trellis-directory:
2427
description: 'Path to Trellis project directory'
2528
required: false

dist/index.js

Lines changed: 11 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/basic.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
ssh-private-key: ${{ secrets.TRELLIS_DEPLOY_SSH_PRIVATE_KEY }}
2121
- uses: roots/setup-trellis-cli@v1
2222
with:
23+
repo-token: ${{ secrets.GITHUB_TOKEN }}
2324
ansible-vault-password: ${{ secrets.ANSIBLE_VAULT_PASSWORD }}
2425
- name: Deploy
2526
run: trellis deploy production

examples/multi-repo.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
ssh-private-key: ${{ secrets.TRELLIS_DEPLOY_SSH_PRIVATE_KEY }}
3333
- uses: roots/setup-trellis-cli@v1
3434
with:
35+
repo-token: ${{ secrets.GITHUB_TOKEN }}
3536
ansible-vault-password: ${{ secrets.ANSIBLE_VAULT_PASSWORD }}
3637
- name: Deploy
3738
run: trellis deploy production

examples/sage.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
ssh-private-key: ${{ secrets.TRELLIS_DEPLOY_SSH_PRIVATE_KEY }}
2626
- uses: roots/setup-trellis-cli@v1
2727
with:
28+
repo-token: ${{ secrets.GITHUB_TOKEN }}
2829
ansible-vault-password: ${{ secrets.ANSIBLE_VAULT_PASSWORD }}
2930
- name: Deploy
3031
run: trellis deploy production

index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function isExactCacheKeyMatch(key, cacheKey) {
1414
return !!(cacheKey && cacheKey.localeCompare(key, undefined, { sensitivity: "accent" }) === 0);
1515
}
1616

17-
async function getRelease(version) {
17+
async function getRelease(version, token) {
1818
let osPlatform = os.platform();
1919
const platformMappings = {
2020
'win32': 'windows'
@@ -29,10 +29,11 @@ async function getRelease(version) {
2929
osArch = archMappings[osArch] || osArch;
3030

3131
core.debug(`Finding release for ${version} (${osPlatform}_${osArch})`);
32-
const release = await fetchRelease(version);
32+
const release = await fetchRelease(version, token);
3333

3434
if (!release.name) {
35-
core.info(`API response: ${JSON.stringify(release)}`);
35+
core.warning(`API response: ${JSON.stringify(release)}`);
36+
core.warning(`If you are hitting API rate limits, see the README for instructions on using a GitHub token.`);
3637
throw new Error(`No trellis-cli release found for version ${version}`);
3738
}
3839

@@ -54,12 +55,14 @@ async function getRelease(version) {
5455
}
5556
}
5657

57-
async function fetchRelease(version) {
58+
async function fetchRelease(version, token) {
5859
const client = new http.HttpClient('setup-trellis-cli-client');
5960

6061
let headers = {};
61-
if (process.env.GITHUB_TOKEN) {
62-
headers['authorization'] = `Bearer ${process.env.GITHUB_TOKEN}`;
62+
if (token !== '') {
63+
headers['authorization'] = `Bearer ${token}`;
64+
} else {
65+
core.warning(`No repo-token provided. We recommend setting one to avoid rate limiting. See the README for instructions.`);
6366
}
6467

6568
let url = null;
@@ -158,9 +161,10 @@ async function run() {
158161
const galaxyInstall = core.getBooleanInput('galaxy-install');
159162
const trellisPath = core.getInput('trellis-directory') || 'trellis';
160163
const version = core.getInput('version') || 'latest';
164+
const token = core.getInput('repo-token');
161165

162166
await core.group('Install trellis-cli', async () => {
163-
const release = await getRelease(version);
167+
const release = await getRelease(version, token);
164168
const cliPath = await downloadRelease(release);
165169
core.addPath(cliPath);
166170
core.debug(`Added ${cliPath} to PATH`);

0 commit comments

Comments
 (0)