Skip to content

Commit 8424957

Browse files
aelawsonhenrybell
andauthored
Add missing project_id input (#50)
This GitHub action is missing the common `project_id` input - I ran into this while trying to setup a deployment workflow on one of my repositories. I added the missing input and then updated the README to reflect it. <!-- Thank you for proposing a pull request! Please note that SOME TESTS WILL LIKELY FAIL due to how GitHub exposes secrets in Pull Requests from forks. Someone from the team will review your Pull Request and respond. Please describe your change and any implementation details below. --> --------- Co-authored-by: henrybell <[email protected]>
1 parent f1740b5 commit 8424957

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ jobs:
163163
used. This is the equivalent of running 'gcloud alpha run' or 'gcloud beta
164164
run'. Valid values are `alpha` or `beta`.
165165

166+
- `project_id`: (Optional) ID of the Google Cloud project in which to deploy the service. The default value is computed from the environment.
167+
166168
## Outputs
167169

168170
- `name`: The full name of the release in Cloud Deploy, including project and

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ inputs:
8484
Additional parameters to supply at release creation time.
8585
required: false
8686

87+
project_id:
88+
description: |-
89+
The Google Cloud Project ID. If unset, this is inherited from the environment.
90+
required: false
91+
8792
flags:
8893
description: |-
8994
Space separated list of other Cloud Deploy flags, examples can be found:

src/main.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,13 @@ export async function run(): Promise<void> {
7777
// Core inputs (required)
7878
const name = getInput('name');
7979
const deliveryPipeline = getInput('delivery_pipeline');
80-
const region = getInput('region');
8180
const source = getInput('source');
8281
const buildArtifacts = getInput('build_artifacts');
8382
const images = parseKVString(getInput('images'));
83+
84+
// Common inputs
85+
const projectId = getInput('project_id');
86+
const region = getInput('region');
8487
const disableInitialRollout = getBooleanInput('disable_initial_rollout');
8588
const sourceStagingDir = getInput('gcs_source_staging_dir');
8689
const skaffoldFile = getInput('skaffold_file');
@@ -114,6 +117,9 @@ export async function run(): Promise<void> {
114117
// Build base command from required inputs
115118
let cmd = ['deploy', 'releases', 'create', name, '--delivery-pipeline', deliveryPipeline];
116119

120+
if (projectId) {
121+
cmd.push('--project', projectId);
122+
}
117123
if (region) {
118124
cmd.push('--region', region);
119125
} else {

tests/unit/main.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { run } from '../../src/main';
3030
const fakeInputs = {
3131
delivery_pipeline: 'delivery-pipeline',
3232
name: 'release-001',
33+
project_id: '',
3334
region: 'us-central1',
3435
source: 'src',
3536
build_artifacts: 'artifacts.json',
@@ -169,6 +170,19 @@ describe('#run', async () => {
169170
assert.rejects(run, 'Both `build_artifacts` and `images` inputs set - please select only one.');
170171
});
171172

173+
it('sets project if given', async (t) => {
174+
const mocks = defaultMocks(t.mock, {
175+
project_id: 'my-test-project',
176+
});
177+
178+
await run();
179+
180+
expectSubArray(mocks.getExecOutput.mock.calls?.at(0)?.arguments?.at(1), [
181+
'--project',
182+
'my-test-project',
183+
]);
184+
});
185+
172186
it('sets region if given', async (t) => {
173187
const mocks = defaultMocks(t.mock, {
174188
region: 'europe-west1',

0 commit comments

Comments
 (0)