Skip to content

Commit

Permalink
Add support for specifying version constraints (#612)
Browse files Browse the repository at this point in the history
This adds support for specifying a version _constraint_ for the version
of gcloud. Since the GitHub Actions runners pre-install a version of
gcloud, this can dramatically reduce CI times.
  • Loading branch information
sethvargo authored Feb 3, 2023
1 parent fb149a7 commit 10b5bd2
Show file tree
Hide file tree
Showing 8 changed files with 333 additions and 2,147 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ jobs:
- name: 'Build'
run: 'npm ci && npm run build'

# No installation
- name: 'Install constraint'
uses: './'
with:
skip_install: true

# Constraint installation
- name: 'Install constraint'
uses: './'
with:
version: '>= 1.0.0'

# Default installation
- name: 'Install version'
uses: './'
Expand Down
41 changes: 37 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:

- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v1'
with:
version: '>= 363.0.0'

- name: 'Use gcloud CLI'
run: 'gcloud info'
Expand All @@ -50,13 +52,42 @@ jobs:
### Cloud SDK inputs
- `version`: (Optional) A string representing the version of the Cloud SDK
(`gcloud`) to install (e.g. `"290.0.1"`). The default value is "latest",
which will install the latest available Cloud SDK version.
- `skip_install`: (Optional) Skip the `gcloud` installation and use the
[system-installed gcloud][github-runners] instead. This can dramatically
improve workflow speeds at the expense of a slightly older gcloud version.
Setting this to `true` ignores any value for the `version` input. Even if
installation is skipped, this GitHub Action will still configure any
components or project metadata. The default value is `false`.

- `version`: (Optional) A string representing the version or version
constraint of the Cloud SDK (`gcloud`) to install (e.g. `"290.0.1"` or `">=
197.0.1"`). The default value is `"latest"`, which will always download and
install the latest available Cloud SDK version.

```yaml
- uses: 'google-github-actions/setup-gcloud@v1'
with:
version: '>= 416.0.0'
```

If there is no installed `gcloud` version that matches the given constraint,
this GitHub Action will download and install the latest available version
that still matches the constraint.

**Warning!** Workload Identity Federation requires version
[363.0.0](https://cloud.google.com/sdk/docs/release-notes#36300_2021-11-02)
or newer.
or newer. If you need support for Workload Identity Federation, specify your
version constraint as such:

```yaml
- uses: 'google-github-actions/setup-gcloud@v1'
with:
version: '>= 363.0.0'
```

You are responsible for ensuring the `gcloud` version matches the features
and components required. See the [gcloud release
notes][gcloud-release-notes] for a full list of versions.

- `project_id`: (Optional) Project ID (**not** project _number_) of the Google
Cloud project. If provided, this will configure the `gcloud` CLI to use that
Expand Down Expand Up @@ -233,3 +264,5 @@ See [LICENSE](LICENSE).
[sa-iam-docs]: https://cloud.google.com/iam/docs/service-accounts
[sa]: https://cloud.google.com/iam/docs/creating-managing-service-accounts
[wif]: https://cloud.google.com/iam/docs/workload-identity-federation
[github-runners]: https://github.com/actions/runner-images
[gcloud-release-notes]: https://cloud.google.com/sdk/docs/release-notes
18 changes: 13 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,28 @@ description: |-
Adds the `gcloud` CLI command to the $PATH.
inputs:
skip_install:
description: |-
Skip installation of the gcloud SDK and use the system-supplied version
instead. The "version" input will be ignored.
default: false
required: false

version:
description: |-
Version of the gcloud SDK to install. If unspecified or set to "latest",
the latest available gcloud SDK version for the target platform will be
installed. Example: "290.0.1".
default: latest
Version or version constraint of the gcloud SDK to install. If
unspecified, it will accept any installed version of the gcloud SDK. If
set to "latest", it will download the latest available SDK. If set to a
version constraint, it will download the latest available version that
matches the constraint. Examples: "290.0.1" or ">= 197.0.1".
default: 'latest'
required: false

project_id:
description: |-
ID of the Google Cloud project. If provided, this will configure gcloud to
use this project ID by default for commands. Individual commands can still
override the project using the --project flag which takes precedence.
default: null
required: false

install_components:
Expand Down
2 changes: 1 addition & 1 deletion dist/main/index.js

Large diffs are not rendered by default.

Loading

0 comments on commit 10b5bd2

Please sign in to comment.