Skip to content

Commit

Permalink
Merge pull request #475 from linode/dev
Browse files Browse the repository at this point in the history
Release 5.41.0
  • Loading branch information
jriddle-linode authored Jun 16, 2023
2 parents 3dc7147 + 7c9e549 commit ac7377e
Show file tree
Hide file tree
Showing 54 changed files with 1,370 additions and 467 deletions.
144 changes: 131 additions & 13 deletions .github/workflows/e2e-suite-pr.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,61 @@
on:
pull_request:
repository_dispatch:
types: [acctest-command]
workflow_dispatch:
inputs:
test_path:
description: 'Test path to be tested: e.g. integration/cli'
required: false
sha:
description: 'The hash value of the commit.'
required: true
pull_request_number:
description: 'The number of the PR.'
required: false

name: PR E2E Tests

jobs:
# Maintainer has commented /acctest on a pull request
integration-fork:
integration-fork-ubuntu:
runs-on: ubuntu-latest
if:
github.event_name == 'repository_dispatch' &&
github.event.client_payload.slash_command.sha != '' &&
github.event.client_payload.pull_request.head.sha == github.event.client_payload.slash_command.sha
github.event_name == 'workflow_dispatch' && inputs.sha != ''

steps:
- uses: actions-ecosystem/action-regex-match@v2
id: validate-tests
with:
text: ${{ github.event.client_payload.slash_command.tests }}
text: ${{ inputs.test_path }}
regex: '[^a-z0-9-:.\/_]' # Tests validation
flags: gi

# Check out merge commit
- name: Checkout PR
uses: actions/checkout@v3
with:
ref: ${{ github.event.client_payload.slash_command.sha }}
ref: ${{ inputs.sha }}

- name: Get the hash value of the latest commit from the PR branch
uses: octokit/[email protected]
id: commit-hash
if: ${{ inputs.pull_request_number != '' }}
with:
query: |
query PRHeadCommitHash($owner: String!, $repo: String!, $pr_num: Int!) {
repository(owner:$owner, name:$repo) {
pullRequest(number: $pr_num) {
headRef {
target {
... on Commit {
oid
}
}
}
}
}
}
owner: ${{ github.event.repository.owner.login }}
repo: ${{ github.event.repository.name }}
pr_num: ${{ fromJSON(inputs.pull_request_number) }}

- name: Update system packages
run: sudo apt-get update -y
Expand All @@ -47,16 +76,16 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- run: make INTEGRATION_TEST_PATH="${{ github.event.client_payload.slash_command.tests }}" testint
- run: make INTEGRATION_TEST_PATH="${{ inputs.test_path }}" testint
if: ${{ steps.validate-tests.outputs.match == '' }}
env:
LINODE_CLI_TOKEN: ${{ secrets.LINODE_TOKEN }}

- uses: actions/github-script@v5
- uses: actions/github-script@v6
id: update-check-run
if: ${{ always() }}
if: ${{ inputs.pull_request_number != '' && fromJson(steps.commit-hash.outputs.data).repository.pullRequest.headRef.target.oid == inputs.sha }}
env:
number: ${{ github.event.client_payload.pull_request.number }}
number: ${{ inputs.pull_request_number }}
job: ${{ github.job }}
conclusion: ${{ job.status }}
with:
Expand All @@ -79,3 +108,92 @@ jobs:
conclusion: process.env.conclusion
});
return result;
integration-fork-windows:
runs-on: windows-latest
if:
github.event_name == 'workflow_dispatch' && inputs.sha != ''

steps:
- uses: actions-ecosystem/action-regex-match@v2
id: validate-tests
with:
text: ${{ inputs.test_path }}
regex: '[^a-z0-9-:.\/_]' # Tests validation
flags: gi

# Check out merge commit
- name: Checkout PR
uses: actions/checkout@v3
with:
ref: ${{ inputs.sha }}

- name: Get the hash value of the latest commit from the PR branch
uses: octokit/[email protected]
id: commit-hash
if: ${{ inputs.pull_request_number != '' }}
with:
query: |
query PRHeadCommitHash($owner: String!, $repo: String!, $pr_num: Int!) {
repository(owner:$owner, name:$repo) {
pullRequest(number: $pr_num) {
headRef {
target {
... on Commit {
oid
}
}
}
}
}
}
owner: ${{ github.event.repository.owner.login }}
repo: ${{ github.event.repository.name }}
pr_num: ${{ fromJSON(inputs.pull_request_number) }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install Python deps
run: pip install -r requirements.txt -r requirements-dev.txt wheel boto3

- name: Install the CLI
run: make install
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- run: make INTEGRATION_TEST_PATH="${{ inputs.test_path }}" testint
env:
LINODE_CLI_TOKEN: ${{ secrets.LINODE_TOKEN_2 }}

- uses: actions/github-script@v6
id: update-check-run
if: ${{ inputs.pull_request_number != '' && fromJson(steps.commit-hash.outputs.data).repository.pullRequest.headRef.target.oid == inputs.sha }}
env:
number: ${{ github.event.client_payload.pull_request.number }}
job: ${{ github.job }}
conclusion: ${{ job.status }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: pull } = await github.rest.pulls.get({
...context.repo,
pull_number: process.env.number
});
const ref = pull.head.sha;
const { data: checks } = await github.rest.checks.listForRef({
...context.repo,
ref
});
const check = checks.check_runs.filter(c => c.name === process.env.job);
const { data: result } = await github.rest.checks.update({
...context.repo,
check_run_id: check[0].id,
status: 'completed',
conclusion: process.env.conclusion
});
return result;
33 changes: 28 additions & 5 deletions .github/workflows/remote-release-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,43 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Get the next minor version
id: semvers
uses: WyriHaximus/github-action-next-semvers@d079934efaf011a4cf8912d4637097fe35d32b93 # pin@v1
- name: Calculate the desired release version
id: calculate_version
uses: actions/github-script@v6
env:
SPEC_VERSION: ${{ github.event.client_payload.spec_version }}
PREVIOUS_CLI_VERSION: ${{ steps.previoustag.outputs.tag }}
with:
result-encoding: string
version: ${{ steps.previoustag.outputs.tag }}
script: |
let spec_version_segments = process.env.SPEC_VERSION.replace("v", "").split(".");
let cli_version_segments = process.env.PREVIOUS_CLI_VERSION.replace("v", "").split(".");
// Default to a patch version bump
let bump_idx = 2;
// This is a minor version bump
if (spec_version_segments[2] == "0") {
bump_idx = 1;
// The patch number should revert to 0
cli_version_segments[2] = "0"
}
// Bump the version
cli_version_segments[bump_idx] = (parseInt(cli_version_segments[bump_idx]) + 1).toString()
return "v" + cli_version_segments.join(".")
- uses: rickstaa/action-create-tag@84c90e6ba79b47b5147dcb11ff25d6a0e06238ba # pin@v1
with:
tag: ${{ steps.semvers.outputs.v_minor }}
tag: ${{ steps.calculate_version.outputs.result }}

- name: Release
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # pin@v1
with:
target_commitish: 'main'
token: ${{ steps.generate_token.outputs.token }}
body: Built from Linode OpenAPI spec ${{ github.event.client_payload.spec_version }}
tag_name: ${{ steps.semvers.outputs.v_minor }}
tag_name: ${{ steps.calculate_version.outputs.result }}
33 changes: 31 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ on:
push:
pull_request:
jobs:
unit-tests:
name: Run unit tests
unit-tests-on-ubuntu:
runs-on: ubuntu-latest
steps:
- name: Clone Repository
Expand Down Expand Up @@ -35,3 +34,33 @@ jobs:

- name: Run the unit test suite
run: make test

unit-tests-on-windows:
runs-on: windows-latest
steps:
- name: Clone Repository
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install Python wheel
run: pip install wheel boto3

- name: Update cert
run: pip install certifi -U

- name: Install deps
run: pip install -r requirements.txt -r requirements-dev.txt

- name: Install Package
shell: pwsh
run: |
make install
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Run the unit test suite
run: make test
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#
# Makefile for more convenient building of the Linode CLI and its baked content
#

INTEGRATION_TEST_PATH :=
TEST_CASE_COMMAND :=

ifdef TEST_CASE
TEST_CASE_COMMAND = -k $(TEST_CASE)
endif


SPEC_VERSION ?= latest
ifndef SPEC
Expand Down Expand Up @@ -49,13 +54,12 @@ testunit:

.PHONY: testint
testint:
pytest tests/integration/${INTEGRATION_TEST_PATH}
pytest tests/integration/${INTEGRATION_TEST_PATH} ${TEST_CASE_COMMAND} --disable-warnings

.PHONY: testall
testall:
pytest tests


# Alias for unit; integration tests should be explicit
.PHONY: test
test: testunit
Expand Down
49 changes: 24 additions & 25 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ you can execute the following::

linode-cli linodes create --region us-east --type g6-nanode-1 --tags tag1 --tags tag2

Lists consisting of nested structures can also be expressed through the command line.
For example, to create a Linode with a public interface on ``eth0`` and a VLAN interface
on ``eth1`` you can execute the following::

linode-cli linodes create \
--region us-east --type g6-nanode-1 --image linode/ubuntu22.04 \
--root_pass "myr00tp4ss123" \
--interfaces.purpose public \
--interfaces.purpose vlan --interfaces.label my-vlan

Specifying Nested Arguments
"""""""""""""""""""""""""""

Expand Down Expand Up @@ -241,6 +251,9 @@ the ``obj`` plugin that ships with the CLI. To do so, simply set
appropriate values. This allows using Linode Object Storage through the CLI
without having a configuration file, which is desirable in some situations.

You may also specify the path to a custom Certificate Authority file using the ``LINODE_CLI_CA``
environment variable.

Configurable API URL
""""""""""""""""""""

Expand Down Expand Up @@ -412,45 +425,31 @@ Testing
with the account. It is only recommended to run these tests if you are an advanced
user.

Installation
^^^^^^^^^^^^

The CLI uses the Bash Automated Testing System (BATS) for testing. To install run the following:

**OSX users**::
Running the Tests
^^^^^^^^^^^^^^^^^

brew install bats-core
Running the tests locally is simple. The only requirements are that you export Linode API token as LINODE_CLI_TOKEN::

**Installing Bats from source**
export LINODE_CLI_TOKEN="your_token"

Check out a copy of the Bats repository. Then, either add the Bats bin directory to your
$PATH, or run the provided install.sh command with the location to the prefix in which you
want to install Bats. For example, to install Bats into /usr/local::

git clone https://github.com/bats-core/bats-core.git
cd bats-core
./install.sh /usr/local

Running the Tests
^^^^^^^^^^^^^^^^^
More information on Managing Linode API tokens can be found here - https://www.linode.com/docs/products/tools/api/guides/manage-api-tokens/

Running the tests is simple. The only requirements are that you have a .linode-cli in your user folder containing your test user token::
In order to run the full integration test, run::

./test/test-runner.sh
make testint

**Running Tests via Docker**
To run specific test package, use environment variable `INTEGRATION_TEST_PATH` with `testint` command::

The openapi spec must first be saved to the base of the linode-cli project:
make INTEGRATION_TEST_PATH="cli" testint

curl -o ./openapi.yaml https://www.linode.com/docs/api/openapi.yaml

Run the following command to build the tests container:

docker build -f Dockerfile-bats -t linode-cli-tests .
Lastly, to run specific test case, use environment variables `TEST_CASE` with `testint` command::

Run the following command to run the test
make TEST_CASE=test_help_page_for_non_aliased_actions testint

docker run -e TOKEN_1=$INSERT_YOUR_TOKEN_HERE -e TOKEN_2=$INSERT_YOUR_TOKEN_HERE --rm linode-cli-tests

Contributing
------------
Expand Down
Loading

0 comments on commit ac7377e

Please sign in to comment.