Skip to content

Commit

Permalink
Merge pull request #28 from digitalocean/v2-experiment
Browse files Browse the repository at this point in the history
digitalocean/action-doctl v2 rewrite
  • Loading branch information
andrewsomething authored Apr 24, 2020
2 parents 54749a3 + 5d1d12c commit 7f3a996
Show file tree
Hide file tree
Showing 11 changed files with 14,378 additions and 57 deletions.
18 changes: 18 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
}
}
80 changes: 72 additions & 8 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,81 @@
on: [push, pull_request]
name: Test and lint

jobs:

build:
name: Lint and test build
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- run: npm test

- name: Checkout master
uses: actions/checkout@master
package_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: "Ensure that code has been packaged and commited"
run: |-
npm install
npm run package
git diff --exit-code dist/index.js || \
(echo -e "\nPlease run 'npm run package' and commit the results" && exit 1)
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@master

- name: Install doctl
uses: ./
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}

- name: Verify installation
run: doctl version

- name: Verify log-in
run: doctl compute region list

test_custom_version_linux_and_mac:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@master

- name: Install doctl
uses: ./
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
version: 1.38.0

- name: Verify installation of correct version
run: |
VERSION=$(doctl version | head -1 | cut -f3 -d' ' | cut -f1 -d'-')
if [ "$VERSION" != "1.38.0" ]; then exit 1; fi
- name: Verify log-in
run: doctl compute region list

test_custom_version_windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@master

- name: Install doctl
uses: ./
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
version: 1.38.0

- name: Lint shell scripts
run: shellcheck *.sh
- name: Verify installation of correct version
run: |
$VERSION = (doctl version | head -1 | cut -f3 -d' ' | cut -f1 -d'-')
If (-NOT ($VERSION -eq "1.38.0")) { exit 1 }
- name: Test build doctl container
run: docker build $GITHUB_WORKSPACE
- name: Verify log-in
run: doctl compute region list
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
.npm
.eslintcache
11 changes: 0 additions & 11 deletions Dockerfile

This file was deleted.

35 changes: 20 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
# GitHub Actions for DigitalOcean

This action enables you to interact with [DigitalOcean](https://www.digitalocean.com/) services via [the `doctl` command-line client](https://github.com/digitalocean/doctl).
This action enables you to interact with [DigitalOcean](https://www.digitalocean.com/) services by installing [the `doctl` command-line client](https://github.com/digitalocean/doctl).

## Usage

As an example, one common use case is retrieving the credentials for a Kubernetes cluster hosted on DigitalOcean for use in a deployment workflow:
To install the latest version of `doctl` and use it in GitHub Actions workflows, add the following step:

```yaml
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
```
`doctl` will now be available in the virtual environment and can be used directly in following steps. As an example, one common use case is retrieving the credentials for a Kubernetes cluster hosted on DigitalOcean for use in a deployment workflow:

```yaml
- name: Save DigitalOcean kubeconfig
uses: digitalocean/action-doctl@master
env:
DIGITALOCEAN_ACCESS_TOKEN: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
with:
args: kubernetes cluster kubeconfig show k8s-cluster-name > $GITHUB_WORKSPACE/.kubeconfig
run: doctl kubernetes cluster kubeconfig save testing-cluster
```

See [this repository](https://github.com/andrewsomething/example-doctl-action) for a full end-to-end example that also demonstrates building the Docker image, pushing it to Docker Hub, and using `kubectl` to deploy to the Kubernetes cluster on DigitalOcean.
See [this repository](https://github.com/do-community/example-doctl-action) for a full end-to-end example that also demonstrates building a Docker image, pushing it to Docker Hub, and using `kubectl` to deploy it to the Kubernetes cluster on DigitalOcean.

### Secrets
### Arguments

- `DIGITALOCEAN_ACCESS_TOKEN` – **Required** A DigitalOcean personal access token ([more info](https://www.digitalocean.com/docs/api/create-personal-access-token/)).
- `token` – (**Required**) A DigitalOcean personal access token ([more info](https://www.digitalocean.com/docs/api/create-personal-access-token/)).
- `version` – (Optional) The version of `doctl` to install. If excluded, the latest release will be used.

### Environment variables
## Contributing

We provide defaults for the following, these may also be overridden:
To install the needed dependencies, run `npm install`. The resulting `node_modules/` directory _is not_ checked in to Git.

- `DIGITALOCEAN_OUTPUT_FORMAT`- **Optional** doctl's output output format, defaults to `json`
Before submitting a pull request, run `npm run package` to package the code [using `ncc`](https://github.com/zeit/ncc#ncc). Packaging assembles the code including dependencies into one file in the `dist/` directory that is checked in to Git.

By default, this action is configured to save output in JSON format to `${HOME}/${GITHUB_ACTION}.${DIGITALOCEAN_OUTPUT_FORMAT}`for consumption by downstream actions.
Pull requests should be made against the `v2` branch.

## License

The Dockerfile and associated scripts and documentation in this project are released under the [MIT License](LICENSE).
This GitHub Action and associated scripts and documentation in this project are released under the [MIT License](LICENSE).
11 changes: 9 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ author: 'Andrew Starr-Bochicchio <asb@digitalocean.com>'
branding:
icon: 'droplet'
color: 'blue'
inputs:
version:
description: 'Version of doctl to install'
default: 'latest'
token:
description: 'DigitalOcean API Token'
required: true
runs:
using: 'docker'
image: 'Dockerfile'
using: 'node12'
main: 'dist/index.js'
Loading

0 comments on commit 7f3a996

Please sign in to comment.