Skip to content

Commit 0c28e4e

Browse files
authored
feat!: transfer App Engine action (#1)
* feat!: transfer App Engine action * Embedd setupGcloudSDK * Run IT not on forks * debug * debug * debug2 * debug3 * add pr check * run if push * Update clean up * Update release please * Add project id
1 parent ba3283d commit 0c28e4e

24 files changed

+4215
-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 -->
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
name: deploy-appengine 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+
deliverables: ${{ github.workspace }}/app.yaml
48+
version: gcloud
49+
promote: false
50+
- name: Test Output
51+
run: |-
52+
curl '${{ steps.deploy.outputs.url }}' \
53+
--silent \
54+
--fail \
55+
--location \
56+
--retry 5 \
57+
--retry-connrefused \
58+
--retry-delay 5 \
59+
--retry-max-time 300
60+
- name: Clean Up
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+
deliverables: ${{ github.workspace }}/app.yaml
100+
version: b64-json
101+
promote: false # Allows for deletion
102+
- name: Test Output
103+
run: |-
104+
curl '${{ steps.deploy.outputs.url }}' \
105+
--silent \
106+
--fail \
107+
--location \
108+
--retry 5 \
109+
--retry-connrefused \
110+
--retry-delay 5 \
111+
--retry-max-time 300
112+
- name: Clean Up
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+
deliverables: ${{ github.workspace }}/app.yaml
152+
version: json
153+
promote: false # Allows for deletion
154+
- name: Test Output
155+
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
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: deploy-appengine Unit
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
run:
7+
name: deploy-appengine
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+
- uses: actions/setup-node@master
15+
with:
16+
node-version: 12.x
17+
- name: npm install
18+
run: npm install
19+
- name: npm lint
20+
run: npm run lint
21+
- name: npm test
22+
run: npm run test
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
6+
name: build and release-please
7+
env:
8+
ACTION_NAME: deploy-appengine
9+
10+
jobs:
11+
update-fork:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: sync fork
15+
uses: actions/checkout@v2
16+
with:
17+
repository: google-github-actions-bot/${{env.ACTION_NAME}}
18+
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
19+
- run: |-
20+
git remote add upstream https://github.com/${GITHUB_REPOSITORY}
21+
git fetch upstream
22+
git checkout main
23+
git reset --hard upstream/main
24+
git rebase upstream/main
25+
git push origin main -f
26+
build:
27+
needs: [update-fork]
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v2
31+
with:
32+
fetch-depth: 0
33+
- run: git pull
34+
- name: install
35+
run: npm install
36+
- name: build
37+
run: npm run build
38+
- name: commit
39+
run: |-
40+
set -e
41+
# get current commit hash
42+
CURRENT_HASH=$(git rev-parse HEAD)
43+
# get last commit hash of last build dist
44+
LAST_BUILD_HASH=$(git log --author=google-github-actions-bot -1 --pretty=format:"%H")
45+
DIFF=""
46+
# build and commit dist if diff
47+
git config --global user.name "actions-bot"
48+
git config user.email '[email protected]'
49+
git add dist/
50+
git diff-index --quiet HEAD || git commit -m "chore: build dist ${ACTION_NAME}"
51+
# if last commit hash of last build dist was found, get logs of commits in btw for PR body
52+
if [ -z "$LAST_BUILD_HASH" ]
53+
then
54+
echo "Unable to find last commit by bot, skipping diff gen"
55+
else
56+
DIFF=$(git log ${LAST_BUILD_HASH}...${CURRENT_HASH} --oneline)
57+
echo $DIFF
58+
fi
59+
# set env vars
60+
echo "CURRENT_HASH=${CURRENT_HASH}" >> $GITHUB_ENV
61+
echo "LAST_BUILD_HASH=${LAST_BUILD_HASH}" >> $GITHUB_ENV
62+
echo 'DIFF<<EOF' >> $GITHUB_ENV
63+
echo "${DIFF}" >> $GITHUB_ENV
64+
echo 'EOF' >> $GITHUB_ENV
65+
- name: Create Pull Request
66+
uses: peter-evans/create-pull-request@v3
67+
with:
68+
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
69+
commit-message: Build dist
70+
author: "actions-bot <[email protected]>"
71+
title: "chore: build dist"
72+
body: |
73+
Build dist PR
74+
${{env.DIFF}}
75+
labels: automated pr
76+
branch: create-pull-request/build-dist
77+
delete-branch: true
78+
push-to-fork: google-github-actions-bot/${{env.ACTION_NAME}}
79+
release-please-pr:
80+
runs-on: ubuntu-latest
81+
needs: [build]
82+
steps:
83+
- uses: google-github-actions/release-please-action@main
84+
with:
85+
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
86+
release-type: node
87+
bump-minor-pre-major: true
88+
fork: true
89+
package-name: ${{env.ACTION_NAME}}
90+
path: ${{env.ACTION_NAME}}
91+
monorepo-tags: ${{env.ACTION_NAME}}
92+
command: release-pr
93+
release-please-release:
94+
runs-on: ubuntu-latest
95+
needs: [build]
96+
steps:
97+
- uses: google-github-actions/release-please-action@main
98+
with:
99+
token: ${{ secrets.GITHUB_TOKEN }}
100+
release-type: node
101+
bump-minor-pre-major: true
102+
package-name: ${{env.ACTION_NAME}}
103+
path: ${{env.ACTION_NAME}}
104+
monorepo-tags: ${{env.ACTION_NAME}}
105+
command: github-release

0 commit comments

Comments
 (0)