Skip to content

Commit b616de9

Browse files
authored
feat: Add working directory input (#21)
1 parent ee5bf41 commit b616de9

File tree

5 files changed

+247
-55
lines changed

5 files changed

+247
-55
lines changed
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
name: deploy-appengine Credentials Integration
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
gcloud:
7+
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name }}
8+
name: with setup-gcloud
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: google-github-actions/setup-gcloud@master
13+
with:
14+
project_id: ${{ secrets.APPENGINE_DEPLOY_PROJECT_ID }}
15+
service_account_key: ${{ secrets.APPENGINE_DEPLOY_SA_KEY_JSON }}
16+
export_default_credentials: true
17+
- name: create app
18+
run: |-
19+
cat <<EOF > ${{ github.workspace }}/app.yaml
20+
service: "${{ github.job }}-${{ github.run_number }}"
21+
runtime: "nodejs10"
22+
EOF
23+
24+
cat <<EOF > ${{ github.workspace }}/server.js
25+
const http = require('http');
26+
const server = http.createServer(function (req, res) {
27+
res.writeHead(200)
28+
res.end('Hello world!');
29+
});
30+
server.listen(process.env.PORT || 8080);
31+
EOF
32+
- name: Build dependency
33+
working-directory: setupGcloudSDK
34+
run: |-
35+
npm install
36+
npm run build
37+
- id: build
38+
name: Build dist
39+
run: |-
40+
npm install
41+
npm run build
42+
- id: deploy
43+
name: Deploy to App Engine
44+
uses: ./
45+
with:
46+
project_id: ${{ secrets.APPENGINE_DEPLOY_PROJECT_ID }}
47+
version: gcloud
48+
promote: false
49+
- name: Test Output
50+
run: |-
51+
curl '${{ steps.deploy.outputs.url }}' \
52+
--silent \
53+
--fail \
54+
--location \
55+
--retry 5 \
56+
--retry-connrefused \
57+
--retry-delay 5 \
58+
--retry-max-time 300
59+
- name: Clean Up
60+
if: ${{ always() }}
61+
run: gcloud app services delete "${{ github.job }}-${{ github.run_number }}" --quiet
62+
63+
b64-json:
64+
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name }}
65+
name: with base64 json creds
66+
runs-on: ubuntu-latest
67+
steps:
68+
- uses: actions/checkout@v2
69+
- name: create app
70+
run: |-
71+
cat <<EOF > ${{ github.workspace }}/app.yaml
72+
service: "${{ github.job }}-${{ github.run_number }}"
73+
runtime: "nodejs10"
74+
EOF
75+
76+
cat <<EOF > ${{ github.workspace }}/server.js
77+
const http = require('http');
78+
const server = http.createServer(function (req, res) {
79+
res.writeHead(200)
80+
res.end('Hello world!');
81+
});
82+
server.listen(process.env.PORT || 8080);
83+
EOF
84+
- name: Build dependency
85+
working-directory: setupGcloudSDK
86+
run: |-
87+
npm install
88+
npm run build
89+
- id: build
90+
name: Build dist
91+
run: |-
92+
npm install
93+
npm run build
94+
- id: deploy
95+
name: Deploy to App Engine
96+
uses: ./
97+
with:
98+
credentials: ${{ secrets.APPENGINE_DEPLOY_SA_KEY_B64 }}
99+
version: b64-json
100+
promote: false # Allows for deletion
101+
- name: Test Output
102+
run: |-
103+
curl '${{ steps.deploy.outputs.url }}' \
104+
--silent \
105+
--fail \
106+
--location \
107+
--retry 5 \
108+
--retry-connrefused \
109+
--retry-delay 5 \
110+
--retry-max-time 300
111+
- name: Clean Up
112+
if: ${{ always() }}
113+
run: gcloud app services delete "${{ github.job }}-${{ github.run_number }}" --quiet
114+
115+
json:
116+
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name }}
117+
name: with json creds
118+
runs-on: ubuntu-latest
119+
steps:
120+
- uses: actions/checkout@v2
121+
- name: create app
122+
run: |-
123+
cat <<EOF > ${{ github.workspace }}/app.yaml
124+
service: "${{ github.job }}-${{ github.run_number }}"
125+
runtime: "nodejs10"
126+
EOF
127+
128+
cat <<EOF > ${{ github.workspace }}/server.js
129+
const http = require('http');
130+
const server = http.createServer(function (req, res) {
131+
res.writeHead(200)
132+
res.end('Hello world!');
133+
});
134+
server.listen(process.env.PORT || 8080);
135+
EOF
136+
- name: Build dependency
137+
working-directory: setupGcloudSDK
138+
run: |-
139+
npm install
140+
npm run build
141+
- id: build
142+
name: Build dist
143+
run: |-
144+
npm install
145+
npm run build
146+
- id: deploy
147+
name: Deploy to App Engine
148+
uses: ./
149+
with:
150+
credentials: ${{ secrets.APPENGINE_DEPLOY_SA_KEY_JSON }}
151+
version: json
152+
promote: false # Allows for deletion
153+
- name: Test Output
154+
run: |-
155+
curl '${{ steps.deploy.outputs.url }}' \
156+
--silent \
157+
--fail \
158+
--location \
159+
--retry 5 \
160+
--retry-connrefused \
161+
--retry-delay 5 \
162+
--retry-max-time 300
163+
- name: Clean Up
164+
if: ${{ always() }}
165+
run: gcloud app services delete "${{ github.job }}-${{ github.run_number }}" --quiet

.github/workflows/deploy-appengine-it.yml

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ name: deploy-appengine Integration
33
on: [push, pull_request]
44

55
jobs:
6-
gcloud:
6+
working-directory:
77
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name }}
8-
name: with setup-gcloud
8+
name: with working directory
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@v2
@@ -16,12 +16,13 @@ jobs:
1616
export_default_credentials: true
1717
- name: create app
1818
run: |-
19-
cat <<EOF > ${{ github.workspace }}/app.yaml
19+
mkdir app
20+
cat <<EOF > ${{ github.workspace }}/app/app.yaml
2021
service: "${{ github.job }}-${{ github.run_number }}"
2122
runtime: "nodejs10"
2223
EOF
2324
24-
cat <<EOF > ${{ github.workspace }}/server.js
25+
cat <<EOF > ${{ github.workspace }}/app/server.js
2526
const http = require('http');
2627
const server = http.createServer(function (req, res) {
2728
res.writeHead(200)
@@ -44,8 +45,7 @@ jobs:
4445
uses: ./
4546
with:
4647
project_id: ${{ secrets.APPENGINE_DEPLOY_PROJECT_ID }}
47-
deliverables: ${{ github.workspace }}/app.yaml
48-
version: gcloud
48+
working_directory: app/
4949
promote: false
5050
- name: Test Output
5151
run: |-
@@ -58,22 +58,29 @@ jobs:
5858
--retry-delay 5 \
5959
--retry-max-time 300
6060
- name: Clean Up
61+
if: ${{ always() }}
6162
run: gcloud app services delete "${{ github.job }}-${{ github.run_number }}" --quiet
6263

63-
b64-json:
64+
deliverable:
6465
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name }}
65-
name: with base64 json creds
66+
name: with deliverable path
6667
runs-on: ubuntu-latest
6768
steps:
6869
- uses: actions/checkout@v2
70+
- uses: google-github-actions/setup-gcloud@master
71+
with:
72+
project_id: ${{ secrets.APPENGINE_DEPLOY_PROJECT_ID }}
73+
service_account_key: ${{ secrets.APPENGINE_DEPLOY_SA_KEY_JSON }}
74+
export_default_credentials: true
6975
- name: create app
7076
run: |-
71-
cat <<EOF > ${{ github.workspace }}/app.yaml
77+
mkdir app
78+
cat <<EOF > ${{ github.workspace }}/app/app.yaml
7279
service: "${{ github.job }}-${{ github.run_number }}"
7380
runtime: "nodejs10"
7481
EOF
7582
76-
cat <<EOF > ${{ github.workspace }}/server.js
83+
cat <<EOF > ${{ github.workspace }}/app/server.js
7784
const http = require('http');
7885
const server = http.createServer(function (req, res) {
7986
res.writeHead(200)
@@ -95,10 +102,9 @@ jobs:
95102
name: Deploy to App Engine
96103
uses: ./
97104
with:
98-
credentials: ${{ secrets.APPENGINE_DEPLOY_SA_KEY_B64 }}
99-
deliverables: ${{ github.workspace }}/app.yaml
100-
version: b64-json
101-
promote: false # Allows for deletion
105+
project_id: ${{ secrets.APPENGINE_DEPLOY_PROJECT_ID }}
106+
deliverables: app/app.yaml
107+
promote: false
102108
- name: Test Output
103109
run: |-
104110
curl '${{ steps.deploy.outputs.url }}' \
@@ -110,29 +116,20 @@ jobs:
110116
--retry-delay 5 \
111117
--retry-max-time 300
112118
- name: Clean Up
119+
if: ${{ always() }}
113120
run: gcloud app services delete "${{ github.job }}-${{ github.run_number }}" --quiet
114-
115-
json:
121+
122+
failure:
116123
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name }}
117-
name: with json creds
124+
name: with bad path
118125
runs-on: ubuntu-latest
119126
steps:
120127
- uses: actions/checkout@v2
121-
- name: create app
122-
run: |-
123-
cat <<EOF > ${{ github.workspace }}/app.yaml
124-
service: "${{ github.job }}-${{ github.run_number }}"
125-
runtime: "nodejs10"
126-
EOF
127-
128-
cat <<EOF > ${{ github.workspace }}/server.js
129-
const http = require('http');
130-
const server = http.createServer(function (req, res) {
131-
res.writeHead(200)
132-
res.end('Hello world!');
133-
});
134-
server.listen(process.env.PORT || 8080);
135-
EOF
128+
- uses: google-github-actions/setup-gcloud@master
129+
with:
130+
project_id: ${{ secrets.APPENGINE_DEPLOY_PROJECT_ID }}
131+
service_account_key: ${{ secrets.APPENGINE_DEPLOY_SA_KEY_JSON }}
132+
export_default_credentials: true
136133
- name: Build dependency
137134
working-directory: setupGcloudSDK
138135
run: |-
@@ -143,23 +140,28 @@ jobs:
143140
run: |-
144141
npm install
145142
npm run build
146-
- id: deploy
147-
name: Deploy to App Engine
143+
- id: cwd
148144
uses: ./
145+
continue-on-error: true
149146
with:
150-
credentials: ${{ secrets.APPENGINE_DEPLOY_SA_KEY_JSON }}
151-
deliverables: ${{ github.workspace }}/app.yaml
152-
version: json
153-
promote: false # Allows for deletion
154-
- name: Test Output
147+
project_id: ${{ secrets.APPENGINE_DEPLOY_PROJECT_ID }}
148+
working_directory: this/path/doesnt/exist/
149+
promote: false
150+
- name: Catch failure
155151
run: |-
156-
curl '${{ steps.deploy.outputs.url }}' \
157-
--silent \
158-
--fail \
159-
--location \
160-
--retry 5 \
161-
--retry-connrefused \
162-
--retry-delay 5 \
163-
--retry-max-time 300
164-
- name: Clean Up
165-
run: gcloud app services delete "${{ github.job }}-${{ github.run_number }}" --quiet
152+
if [ ${{ steps.cwd.outcome }} != 'failure' ]; then
153+
exit 1
154+
fi
155+
- id: deliverable
156+
uses: ./
157+
continue-on-error: true
158+
with:
159+
project_id: ${{ secrets.APPENGINE_DEPLOY_PROJECT_ID }}
160+
deliverables: this/path/doesnt/exist/app.yaml
161+
promote: false
162+
- name: Catch failure
163+
run: |-
164+
if [ ${{ steps.deliverable.outcome }} != 'failure' ]; then
165+
exit 1
166+
fi
167+

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ steps:
4646
- `project_id`: (Optional) ID of the Google Cloud project. If provided, this
4747
will override the project configured by gcloud.
4848

49+
- `working_directory`: (Optional) The working directory to use. **Actions do not honor
50+
[default working-directory settings](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#defaultsrun).** The `deliverables` input is a
51+
relative path based on this setting.
52+
4953
- `deliverables`: (Optional) The [yaml files](https://cloud.google.com/appengine/docs/standard/nodejs/configuration-files#optional_configuration_files)
5054
for the services or configurations you want to deploy. If not given, defaults
5155
to app.yaml in the current directory. If that is not found, attempts to
@@ -207,3 +211,5 @@ Migrated to `deploy-appengine`:
207211
[gh-runners]: https://help.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners
208212
[gh-secret]: https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets
209213
[setup-gcloud]: https://github.com/google-github-actions/setup-gcloud/
214+
[roles]: https://cloud.google.com/iam/docs/granting-roles-to-service-accounts#granting_access_to_a_service_account_for_a_resource
215+
[create-key]: https://cloud.google.com/iam/docs/creating-managing-service-account-keys

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ inputs:
2222
description: The GCP project ID. Overrides project ID set by credentials.
2323
required: true
2424

25+
working_directory:
26+
description: |-
27+
The path to set the working directory. The deliverables will be referenced
28+
from this path.
29+
required: false
30+
2531
deliverables:
2632
description: |-
2733
The yaml files for the services or configurations you want to deploy.

0 commit comments

Comments
 (0)