Skip to content

Commit 9741a48

Browse files
authored
feat!: transfer cf action (#1)
* init action * fix test function path * new build workflow * address comments * fix path
1 parent b2b256f commit 9741a48

26 files changed

+4536
-0
lines changed

.eslintrc.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
module.exports = {
18+
root: true,
19+
parser: '@typescript-eslint/parser',
20+
plugins: ['@typescript-eslint'],
21+
extends: [
22+
'eslint:recommended',
23+
'plugin:@typescript-eslint/eslint-recommended',
24+
'plugin:@typescript-eslint/recommended',
25+
'plugin:prettier/recommended',
26+
'prettier/@typescript-eslint',
27+
],
28+
};

.github/ISSUE_TEMPLATE/bug.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
name: Bug report
3+
about: Tell us about a bug.
4+
labels: bug
5+
---
6+
7+
### TL;DR
8+
<!-- Describe the bug in 1-2 sentences below. -->
9+
10+
**Expected behavior**
11+
<!-- What did you expect to happen? Please share below. -->
12+
13+
**Observed behavior**
14+
<!-- What did happened instead? Please share below. -->
15+
16+
17+
### Reproduction
18+
19+
**Action YAML**
20+
<!-- Add your complete GitHub Actions YAML below. -->
21+
22+
```yaml
23+
# Paste your complete GitHub Actions YAML here, removing
24+
# any sensitive values.
25+
```
26+
27+
**Repository**
28+
<!-- Is your repository public? If so, please link to it. -->
29+
<!-- If your repository is not public, delete this section. -->
30+
31+
32+
**Additional information**
33+
<!-- Are you running custom workers? Doing something atypical? Etc? -->

.github/ISSUE_TEMPLATE/feature.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
name: Feature
3+
about: Request a new feature or functionality.
4+
labels: feature
5+
---
6+
7+
### TL;DR
8+
<!-- Describe the feature in 1-2 sentences below. -->
9+
10+
11+
### Design
12+
13+
**Action YAML**
14+
<!-- What do you envision the action to look like? -->
15+
<!-- If this is not relevant, delete this section. -->
16+
17+
```yaml
18+
# Paste your proposed GitHub Actions YAML here.
19+
```
20+
21+
**Resources**
22+
<!-- Please provide links to relevant documentation or examples. -->
23+
24+
- [Link to documentation](TODO)
25+
26+
27+
**Additional information**
28+
<!-- Are you running custom workers? Doing something atypical? Etc? -->

.github/ISSUE_TEMPLATE/question.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
name: Question
3+
about: Ask us a question.
4+
labels: question
5+
---
6+
7+
### Question
8+
<!-- Ask your question in 1-2 sentences below. -->
9+
<!-- If sharing code, please use ``` codeblocks -->

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

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: deploy-cloud-functions Integration
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
gcloud:
7+
name: with setup-gcloud
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: google-github-actions/setup-gcloud@master # Set up ADC for credentials
12+
with:
13+
service_account_email: ${{ secrets.DEPLOY_CF_SA_EMAIL }}
14+
service_account_key: ${{ secrets.DEPLOY_CF_SA_KEY_JSON }}
15+
export_default_credentials: true
16+
- id: build
17+
name: Build dist
18+
run: |-
19+
npm install
20+
npm run build
21+
- id: deploy
22+
uses: ./
23+
with:
24+
name: cf-http-gcloud-${{ github.run_number }}
25+
runtime: nodejs10
26+
entry_point: helloWorld
27+
source_dir: ./tests/test-node-func/
28+
- uses: actions/setup-node@master
29+
with:
30+
node-version: 12.x
31+
- run: npm install
32+
- name: integration tests
33+
run: npm run e2e-tests
34+
env:
35+
URL: ${{ steps.deploy.outputs.url }}
36+
- name: integration test clean up
37+
run: npm run cleanup
38+
env:
39+
DEPLOY_CF_SA_KEY_JSON: ${{ secrets.DEPLOY_CF_SA_KEY_JSON }}
40+
CF_NAME: projects/${{ secrets.DEPLOY_CF_PROJECT_ID }}/locations/us-central1/functions/cf-http-gcloud-${{ github.run_number }}
41+
42+
b64_json:
43+
name: with base64 json creds
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v2
47+
- id: build
48+
name: Build dist
49+
run: |-
50+
npm install
51+
npm run build
52+
- id: deploy
53+
uses: ./
54+
with:
55+
name: cf-http-b64-${{ github.run_number }}
56+
runtime: nodejs10
57+
entry_point: helloWorld
58+
source_dir: ./tests/test-node-func/
59+
credentials: ${{ secrets.DEPLOY_CF_SA_KEY_B64 }}
60+
- uses: actions/setup-node@master
61+
with:
62+
node-version: 12.x
63+
- run: npm install
64+
- uses: google-github-actions/setup-gcloud@master # Set up ADC to make authenticated request to service
65+
with:
66+
service_account_email: ${{ secrets.DEPLOY_CF_SA_EMAIL }}
67+
service_account_key: ${{ secrets.DEPLOY_CF_SA_KEY_JSON }}
68+
export_default_credentials: true
69+
- name: integration tests
70+
run: npm run e2e-tests
71+
env:
72+
URL: ${{ steps.deploy.outputs.url }}
73+
- name: integration test clean up
74+
run: npm run cleanup
75+
env:
76+
DEPLOY_CF_SA_KEY_JSON: ${{ secrets.DEPLOY_CF_SA_KEY_JSON }}
77+
CF_NAME: projects/${{ secrets.DEPLOY_CF_PROJECT_ID }}/locations/us-central1/functions/cf-http-b64-${{ github.run_number }}
78+
79+
json:
80+
name: with json creds
81+
runs-on: ubuntu-latest
82+
steps:
83+
- uses: actions/checkout@v2
84+
- id: build
85+
name: Build dist
86+
run: |-
87+
npm install
88+
npm run build
89+
- id: deploy
90+
uses: ./
91+
with:
92+
name: cf-http-json-${{ github.run_number }}
93+
runtime: nodejs10
94+
entry_point: helloWorld
95+
source_dir: ./tests/test-node-func/
96+
credentials: ${{ secrets.DEPLOY_CF_SA_KEY_JSON }}
97+
- uses: actions/setup-node@master
98+
with:
99+
node-version: 12.x
100+
- run: npm install
101+
- uses: google-github-actions/setup-gcloud@master # Set up ADC to make authenticated request to service
102+
with:
103+
service_account_email: ${{ secrets.DEPLOY_CF_SA_EMAIL }}
104+
service_account_key: ${{ secrets.DEPLOY_CF_SA_KEY_JSON }}
105+
export_default_credentials: true
106+
- name: integration tests
107+
run: npm run e2e-tests
108+
env:
109+
URL: ${{ steps.deploy.outputs.url }}
110+
- name: integration test clean up
111+
run: npm run cleanup
112+
env:
113+
DEPLOY_CF_SA_KEY_JSON: ${{ secrets.DEPLOY_CF_SA_KEY_JSON }}
114+
CF_NAME: projects/${{ secrets.DEPLOY_CF_PROJECT_ID }}/locations/us-central1/functions/cf-http-json-${{ github.run_number }}
115+

.github/workflows/deploy-cf-unit.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: deploy-cloud-functions Unit
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
run:
7+
name: test
8+
runs-on: ${{ matrix.operating-system }}
9+
strategy:
10+
matrix:
11+
operating-system: [ubuntu-latest, windows-latest, macos-latest]
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- uses: actions/setup-node@master
16+
with:
17+
node-version: 12.x
18+
19+
- name: npm install
20+
run: npm install
21+
22+
- name: npm lint
23+
run: npm run lint
24+
25+
- uses: google-github-actions/setup-gcloud@master
26+
with:
27+
service_account_email: ${{ secrets.DEPLOY_CF_SA_EMAIL }}
28+
service_account_key: ${{ secrets.DEPLOY_CF_SA_KEY_B64 }}
29+
export_default_credentials: true
30+
- name: npm test
31+
run: npm run test
32+
env:
33+
DEPLOY_CF_SA_KEY_JSON: ${{ secrets.DEPLOY_CF_SA_KEY_JSON }}
34+
GCLOUD_PROJECT: ${{ secrets.DEPLOY_CF_PROJECT_ID }}
35+
DEPLOY_CF_EVENT_PUBSUB_TOPIC: ${{ secrets.DEPLOY_CF_EVENT_PUBSUB_TOPIC }}

.github/workflows/release-please.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
name: build and release-please
6+
jobs:
7+
build:
8+
env:
9+
ACTION_NAME: deploy-cloud-functions
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
with:
14+
fetch-depth: 0
15+
- run: git pull
16+
- name: install
17+
run: npm install
18+
- name: build
19+
run: npm run build
20+
- name: commit
21+
run: |-
22+
set -e
23+
# get current commit hash
24+
CURRENT_HASH=$(git rev-parse HEAD)
25+
# get last commit hash of last build dist
26+
LAST_BUILD_HASH=$(git log --author=google-github-actions-bot -1 --pretty=format:"%H")
27+
DIFF=""
28+
# build and commit dist if diff
29+
git config --global user.name "actions-bot"
30+
git config user.email '[email protected]'
31+
git add dist/
32+
git diff-index --quiet HEAD || git commit -m "chore: build dist ${ACTION_NAME}"
33+
# if last commit hash of last build dist was found, get logs of commits in btw for PR body
34+
if [ -z "$LAST_BUILD_HASH" ]
35+
then
36+
echo "Unable to find last commit by bot, skipping diff gen"
37+
else
38+
DIFF=$(git log ${LAST_BUILD_HASH}...${CURRENT_HASH} --oneline)
39+
echo $DIFF
40+
fi
41+
# set env vars
42+
echo "CURRENT_HASH=${CURRENT_HASH}" >> $GITHUB_ENV
43+
echo "LAST_BUILD_HASH=${LAST_BUILD_HASH}" >> $GITHUB_ENV
44+
echo 'DIFF<<EOF' >> $GITHUB_ENV
45+
echo "${DIFF}" >> $GITHUB_ENV
46+
echo 'EOF' >> $GITHUB_ENV
47+
- name: Create Pull Request
48+
uses: peter-evans/create-pull-request@v3
49+
with:
50+
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
51+
commit-message: Build dist
52+
author: "actions-bot <[email protected]>"
53+
title: "chore: build dist"
54+
body: |
55+
Build dist PR
56+
${{env.DIFF}}
57+
labels: automated pr
58+
branch: create-pull-request/build-dist
59+
delete-branch: true
60+
push-to-fork: google-github-actions-bot/${{env.ACTION_NAME}}
61+
release-please-pr:
62+
runs-on: ubuntu-latest
63+
needs: [build]
64+
steps:
65+
- uses: google-github-actions/release-please-action@main
66+
with:
67+
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
68+
release-type: node
69+
fork: true
70+
package-name: ${{env.ACTION_NAME}}
71+
path: ${{env.ACTION_NAME}}
72+
monorepo-tags: ${{env.ACTION_NAME}}
73+
command: release-pr
74+
release-please-release:
75+
runs-on: ubuntu-latest
76+
needs: [build]
77+
steps:
78+
- uses: google-github-actions/release-please-action@main
79+
with:
80+
token: ${{ secrets.GITHUB_TOKEN }}
81+
release-type: node
82+
package-name: ${{env.ACTION_NAME}}
83+
path: ${{env.ACTION_NAME}}
84+
monorepo-tags: ${{env.ACTION_NAME}}
85+
command: github-release

.gitignore

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
node_modules/
2+
runner/
3+
4+
# Rest of the file pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
yarn-debug.log*
10+
yarn-error.log*
11+
lerna-debug.log*
12+
13+
# Diagnostic reports (https://nodejs.org/api/report.html)
14+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
15+
16+
# Runtime data
17+
pids
18+
*.pid
19+
*.seed
20+
*.pid.lock
21+
22+
# Directory for instrumented libs generated by jscoverage/JSCover
23+
lib-cov
24+
25+
# Coverage directory used by tools like istanbul
26+
coverage
27+
*.lcov
28+
29+
# TypeScript v1 declaration files
30+
typings/
31+
32+
# TypeScript cache
33+
*.tsbuildinfo
34+
35+
# Optional npm cache directory
36+
.npm
37+
38+
# Optional eslint cache
39+
.eslintcache
40+
41+
# Optional REPL history
42+
.node_repl_history
43+
44+
# Output of 'npm pack'
45+
*.tgz

0 commit comments

Comments
 (0)