Skip to content

Commit

Permalink
remove GITHUB_TOKEN autoauth and ensure lando update exit codes nonze…
Browse files Browse the repository at this point in the history
…ro on update check fails (#141)

* write failing test for lando update GITHUB_TOKEN issue

* write failing test for lando update GITHUB_TOKEN issue part 2

* write failing test for lando update GITHUB_TOKEN issue part 3

* write failing test for lando update GITHUB_TOKEN issue part 4

* change octokit/rest to use LANDO_GITHUB_TOKEN if set
  • Loading branch information
pirog committed Oct 10, 2024
1 parent 7f1a6f7 commit b93a0c3
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 3 deletions.
1 change: 0 additions & 1 deletion .github/workflows/pr-core-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
- examples/plugin-commands
- examples/services
- examples/tooling
- examples/update
node-version:
- "18"
os:
Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/pr-update-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Update Tests

on:
pull_request:

jobs:
leia-tests:
runs-on: ${{ matrix.os }}
env:
TERM: xterm
strategy:
fail-fast: false
matrix:
lando-version:
- 3-slim
# uncomment to test against bleeding edge cli
# - 3-dev-slim
leia-test:
- examples/update
node-version:
- "18"
os:
# - macos-13
# - macos-14
- ubuntu-22.04
# - windows-2022
shell:
- bash

steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install node ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org
cache: npm
- name: Install dependencies
run: npm clean-install --prefer-offline --frozen-lockfile
# bundle deps is needed so local plugin installation succeeds
- name: Bundle Deps
uses: lando/prepare-release-action@v3
with:
lando-plugin: true
version: dev
sync: false
- name: Setup lando ${{ matrix.lando-version }}
uses: lando/setup-lando@v3
with:
lando-version: ${{ matrix.lando-version }}
telemetry: false
config: |
setup.skipCommonPlugins=true
setup.plugins.@lando/core=${{ github.workspace }}
- name: Run Leia Tests
uses: lando/run-leia-action@v2
with:
leia-test: "./${{ matrix.leia-test }}/README.md"
cleanup-header: "Destroy tests"
shell: ${{ matrix.shell }}
stdin: true
3 changes: 3 additions & 0 deletions examples/update/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ lando version -c "@lando/php" | grep -q "v0.9.0"
# Should be able to run lando update and update legacy plugin.
lando update -y
lando version -c "@lando/php" | grep -qv "v0.9.0"

# Should be able to run lando update with a bogus GITHUB_TOKEN
GITHUB_TOKEN="BROKEN TOKEN" lando update -y
```
5 changes: 3 additions & 2 deletions lib/updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ module.exports = class UpdateManager {

checks.push(new Promise(async resolve => {
// summon the katkraken
const octokit = new Octokit({auth: get(process, 'env.GITHUB_TOKEN')});
const octokit = new Octokit({auth: get(process, 'env.LANDO_GITHUB_TOKEN')});
// check internet connection
const online = await require('is-online')();
// throw error if not online
Expand All @@ -115,6 +115,7 @@ module.exports = class UpdateManager {
}

const {data, status, url} = await octokit.rest.repos.listReleases({owner: 'lando', repo: 'cli'});
console.log(await octokit.rest.repos.listReleases({owner: 'lando', repo: 'cli'}));
this.debug('retrieved cli information from %o [%o]', url, status);

const versions = data
Expand Down Expand Up @@ -302,7 +303,7 @@ module.exports = class UpdateManager {
});

// summon the katkraken
const octokit = new Octokit({auth: get(process, 'env.GITHUB_TOKEN')});
const octokit = new Octokit({auth: get(process, 'env.LANDO_GITHUB_TOKEN')});

// get latest
try {
Expand Down
8 changes: 8 additions & 0 deletions tasks/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ module.exports = lando => {

// resolve to unique and installable list of items
const tasks = await lando.updates.getUpdateTasks();

// try to update the plugins
const {errors, results} = await lando.runTasks(tasks, {
renderer: 'lando',
Expand All @@ -156,6 +157,13 @@ module.exports = lando => {
lando.cli.clearTaskCaches();
lando.cache.remove('updates-2');

// throw an error if there is an update error
if (items.filter(item => item.state === 'ERROR').length > 0) {
const badcheck = items.find(item => item.state === 'ERROR');
lando.log.debug('an update error check occured with %o', badcheck.update);
lando.exitCode = 14;
}

// we didnt have to do anything
if (errors.length === 0 && results.length === 0) {
console.log(`As far as ${color.bold('lando update')} can tell you are already ${color.green('up to date!')}`);
Expand Down

0 comments on commit b93a0c3

Please sign in to comment.