Skip to content

Commit bd33506

Browse files
authored
Add core functionality (#1)
This PR adds core GitHub Actions functionality, along with unit/integration tests.
1 parent aa3c895 commit bd33506

23 files changed

+5037
-1
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 2023 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+
],
27+
ignorePatterns: ['**/dist/*'],
28+
};

.github/dependabot.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "npm"
9+
directory: "/"
10+
commit-message:
11+
prefix: "chore(deps): "
12+
rebase-strategy: "disabled"
13+
schedule:
14+
interval: "daily"
15+
ignore:
16+
- dependency-name: "*"
17+
update-types: ["version-update:semver-patch", "version-update:semver-minor"] # Security updates are unaffected by this setting

.github/workflows/draft-release.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: 'Draft release'
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version_strategy:
7+
description: 'Version strategy: The strategy to used to update the version based on semantic versioning (more info at https://semver.org/).'
8+
required: true
9+
default: 'patch'
10+
type: 'choice'
11+
options:
12+
- 'major'
13+
- 'minor'
14+
- 'patch'
15+
16+
jobs:
17+
draft-release:
18+
name: 'Draft release'
19+
uses: 'google-github-actions/.github/.github/workflows/draft-release.yml@v0'
20+
with:
21+
version_strategy: '${{ github.event.inputs.version_strategy }}'
22+
# secrets must be explicitly passed to reusable workflows https://docs.github.com/en/enterprise-cloud@latest/actions/using-workflows/reusing-workflows#using-inputs-and-secrets-in-a-reusable-workflow
23+
secrets:
24+
ACTIONS_BOT_TOKEN: '${{ secrets.ACTIONS_BOT_TOKEN }}'

.github/workflows/integration.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: 'Integration'
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
pull_request:
8+
branches:
9+
- 'main'
10+
workflow_dispatch:
11+
12+
concurrency:
13+
group: '${{ github.workflow }}-${{ github.head_ref || github.ref }}'
14+
cancel-in-progress: true
15+
16+
permissions:
17+
contents: 'read'
18+
id-token: 'write'
19+
20+
env:
21+
REGION: 'us-central1'
22+
23+
jobs:
24+
test:
25+
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name && github.actor != 'dependabot[bot]' }}
26+
runs-on: 'ubuntu-latest'
27+
28+
steps:
29+
- id: 'checkout'
30+
name: 'Checkout'
31+
uses: 'actions/checkout@v3'
32+
33+
- id: 'compute-test-uid'
34+
name: 'Compute test UID'
35+
run: |-
36+
echo "TEST_UID=${GITHUB_JOB}-${GITHUB_SHA::7}-${GITHUB_RUN_NUMBER}" >> ${GITHUB_ENV}
37+
38+
- id: 'set-up-node'
39+
name: 'Set up Node'
40+
uses: 'actions/setup-node@v3'
41+
with:
42+
node-version: '16.x'
43+
44+
- id: 'build'
45+
name: 'Build'
46+
run: 'npm ci && npm run build'
47+
48+
- id: 'auth'
49+
name: 'Auth'
50+
uses: 'google-github-actions/auth@v1'
51+
with:
52+
workload_identity_provider: '${{ secrets.WIF_PROVIDER_NAME }}'
53+
service_account: '${{ secrets.SERVICE_ACCOUNT_EMAIL }}'
54+
55+
- id: 'gcloud-setup'
56+
name: 'Set up Cloud SDK'
57+
uses: 'google-github-actions/setup-gcloud@main'
58+
with:
59+
project_id: '${{ secrets.PROJECT_ID }}'
60+
61+
- id: 'populate-pipeline-template'
62+
name: 'Populate values in template for Cloud Deploy pipeline and target'
63+
run: 'envsubst < tests/fixtures/clouddeploy.yaml.template > tests/fixtures/clouddeploy.yaml'
64+
env:
65+
PROJECT_ID: '${{ secrets.PROJECT_ID }}'
66+
REGION: '${{ env.REGION }}'
67+
68+
- id: 'create-pipeline'
69+
name: 'Create pipeline'
70+
run: 'gcloud deploy apply --file=tests/fixtures/clouddeploy.yaml --region=${REGION}'
71+
72+
- id: 'create-release'
73+
name: 'Create release'
74+
uses: './'
75+
with:
76+
name: '${{ env.TEST_UID }}'
77+
region: '${{ env.REGION }}'
78+
delivery_pipeline: 'gha-test-pipeline'
79+
source: 'tests/fixtures/'
80+
images: 'gha-test-app=gcr.io/cloudrun/hello:latest'
81+
description: 'GHA test ${{ env.TEST_UID }}'
82+
disable_initial_rollout: true
83+
labels: |-
84+
label1=value1
85+
annotations: |-
86+
annotation1=value1
87+
88+
- id: 'report-release'
89+
name: 'Report Cloud Deploy release'
90+
run: |-
91+
echo "Created release: ${{ steps.create-release.outputs.name }}"
92+
echo "Release link: ${{ steps.create-release.outputs.link }}"
93+
94+
- id: 'run-e2e-tests'
95+
name: 'Run Tests'
96+
run: 'npm run e2e-tests'
97+
env:
98+
ANNOTATIONS: '{"git-sha":"${{ github.sha }}", "annotation1":"value1"}'
99+
DELIVERY_PIPELINE: 'gha-test-pipeline'
100+
DESCRIPTION: 'GHA test ${{ env.TEST_UID }}'
101+
IMAGES: 'gha-test-app=gcr.io/cloudrun/hello:latest'
102+
LABELS: '{"managed-by":"github-actions", "label1":"value1"}'
103+
NAME: 'projects/${{ secrets.PROJECT_ID }}/locations/${{ env.REGION }}/deliveryPipelines/gha-test-pipeline/releases/${{ env.TEST_UID }}'
104+
PROJECT_ID: '${{ secrets.PROJECT_ID }}'
105+
REGION: '${{ env.REGION }}'

.github/workflows/release.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: 'Release'
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
8+
jobs:
9+
release:
10+
if: "startsWith(github.event.head_commit.message, 'Release: v')"
11+
name: 'Release'
12+
uses: 'google-github-actions/.github/.github/workflows/release.yml@v0'

.github/workflows/unit.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: 'Unit'
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
pull_request:
8+
branches:
9+
- 'main'
10+
workflow_dispatch:
11+
12+
concurrency:
13+
group: '${{ github.workflow }}-${{ github.head_ref || github.ref }}'
14+
cancel-in-progress: true
15+
16+
jobs:
17+
unit:
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
os:
22+
- 'ubuntu-latest'
23+
- 'windows-latest'
24+
- 'macos-latest'
25+
runs-on: '${{ matrix.os }}'
26+
27+
steps:
28+
- uses: 'actions/checkout@v3'
29+
30+
- uses: 'actions/setup-node@v3'
31+
with:
32+
node-version: '16.x'
33+
34+
- name: 'npm build'
35+
run: 'npm ci && npm run build'
36+
37+
- name: 'npm lint'
38+
# There's no need to run the linter for each operating system, since it
39+
# will find the same thing 3x and clog up the PR review.
40+
if: ${{ matrix.os == 'ubuntu-latest' }}
41+
run: 'npm run lint'
42+
43+
- name: 'npm test'
44+
run: 'npm run test'

.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/main/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

.prettierrc.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2023 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+
arrowParens: 'always',
19+
bracketSpacing: true,
20+
endOfLine: 'auto',
21+
jsxSingleQuote: true,
22+
printWidth: 100,
23+
quoteProps: 'consistent',
24+
semi: true,
25+
singleQuote: true,
26+
tabWidth: 2,
27+
trailingComma: 'all',
28+
useTabs: false,
29+
};

0 commit comments

Comments
 (0)