Skip to content

Commit 10b5bd2

Browse files
authored
Add support for specifying version constraints (#612)
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.
1 parent fb149a7 commit 10b5bd2

File tree

8 files changed

+333
-2147
lines changed

8 files changed

+333
-2147
lines changed

.github/workflows/integration.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ jobs:
3838
- name: 'Build'
3939
run: 'npm ci && npm run build'
4040

41+
# No installation
42+
- name: 'Install constraint'
43+
uses: './'
44+
with:
45+
skip_install: true
46+
47+
# Constraint installation
48+
- name: 'Install constraint'
49+
uses: './'
50+
with:
51+
version: '>= 1.0.0'
52+
4153
# Default installation
4254
- name: 'Install version'
4355
uses: './'

README.md

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ jobs:
4141

4242
- name: 'Set up Cloud SDK'
4343
uses: 'google-github-actions/setup-gcloud@v1'
44+
with:
45+
version: '>= 363.0.0'
4446

4547
- name: 'Use gcloud CLI'
4648
run: 'gcloud info'
@@ -50,13 +52,42 @@ jobs:
5052
5153
### Cloud SDK inputs
5254
53-
- `version`: (Optional) A string representing the version of the Cloud SDK
54-
(`gcloud`) to install (e.g. `"290.0.1"`). The default value is "latest",
55-
which will install the latest available Cloud SDK version.
55+
- `skip_install`: (Optional) Skip the `gcloud` installation and use the
56+
[system-installed gcloud][github-runners] instead. This can dramatically
57+
improve workflow speeds at the expense of a slightly older gcloud version.
58+
Setting this to `true` ignores any value for the `version` input. Even if
59+
installation is skipped, this GitHub Action will still configure any
60+
components or project metadata. The default value is `false`.
61+
62+
- `version`: (Optional) A string representing the version or version
63+
constraint of the Cloud SDK (`gcloud`) to install (e.g. `"290.0.1"` or `">=
64+
197.0.1"`). The default value is `"latest"`, which will always download and
65+
install the latest available Cloud SDK version.
66+
67+
```yaml
68+
- uses: 'google-github-actions/setup-gcloud@v1'
69+
with:
70+
version: '>= 416.0.0'
71+
```
72+
73+
If there is no installed `gcloud` version that matches the given constraint,
74+
this GitHub Action will download and install the latest available version
75+
that still matches the constraint.
5676

5777
**Warning!** Workload Identity Federation requires version
5878
[363.0.0](https://cloud.google.com/sdk/docs/release-notes#36300_2021-11-02)
59-
or newer.
79+
or newer. If you need support for Workload Identity Federation, specify your
80+
version constraint as such:
81+
82+
```yaml
83+
- uses: 'google-github-actions/setup-gcloud@v1'
84+
with:
85+
version: '>= 363.0.0'
86+
```
87+
88+
You are responsible for ensuring the `gcloud` version matches the features
89+
and components required. See the [gcloud release
90+
notes][gcloud-release-notes] for a full list of versions.
6091

6192
- `project_id`: (Optional) Project ID (**not** project _number_) of the Google
6293
Cloud project. If provided, this will configure the `gcloud` CLI to use that
@@ -233,3 +264,5 @@ See [LICENSE](LICENSE).
233264
[sa-iam-docs]: https://cloud.google.com/iam/docs/service-accounts
234265
[sa]: https://cloud.google.com/iam/docs/creating-managing-service-accounts
235266
[wif]: https://cloud.google.com/iam/docs/workload-identity-federation
267+
[github-runners]: https://github.com/actions/runner-images
268+
[gcloud-release-notes]: https://cloud.google.com/sdk/docs/release-notes

action.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,28 @@ description: |-
1919
Adds the `gcloud` CLI command to the $PATH.
2020
2121
inputs:
22+
skip_install:
23+
description: |-
24+
Skip installation of the gcloud SDK and use the system-supplied version
25+
instead. The "version" input will be ignored.
26+
default: false
27+
required: false
28+
2229
version:
2330
description: |-
24-
Version of the gcloud SDK to install. If unspecified or set to "latest",
25-
the latest available gcloud SDK version for the target platform will be
26-
installed. Example: "290.0.1".
27-
default: latest
31+
Version or version constraint of the gcloud SDK to install. If
32+
unspecified, it will accept any installed version of the gcloud SDK. If
33+
set to "latest", it will download the latest available SDK. If set to a
34+
version constraint, it will download the latest available version that
35+
matches the constraint. Examples: "290.0.1" or ">= 197.0.1".
36+
default: 'latest'
2837
required: false
2938

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

3846
install_components:

dist/main/index.js

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

0 commit comments

Comments
 (0)