Skip to content

Commit 792f1bb

Browse files
committed
content copied from hello-world-api embeded action
1 parent 140b3ba commit 792f1bb

File tree

9 files changed

+366
-3
lines changed

9 files changed

+366
-3
lines changed

.github/workflows/test.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# I really don't know the best way to test this, so commenting it all out for now.
2+
# A test would require setting up an application (probably with terraform).
3+
# Just use https://github.com/byu-oit/hello-world-api and https://github.com/byu-oit/hw-lambda-api to test for now.
4+
5+
# name: "Test"
6+
# on:
7+
# push:
8+
# branches:
9+
# - master
10+
11+
# jobs:
12+
# test:
13+
# name: Test
14+
# runs-on: ubuntu-latest
15+
# steps:
16+
# - uses: actions/checkout@v1
17+
# - name: CodeDeploy
18+
# uses: ./
19+
# with:
20+
# application-name: some-cd-app
21+
# deployment-group-name: some-cd-group
22+
# appspec-file: some-appspec-file

.gitignore

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
node_modules/
2+
3+
# Editors
4+
.vscode
5+
.idea
6+
7+
# Logs
8+
logs
9+
*.log
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
14+
# Runtime data
15+
pids
16+
*.pid
17+
*.seed
18+
*.pid.lock
19+
20+
# Directory for instrumented libs generated by jscoverage/JSCover
21+
lib-cov
22+
23+
# Coverage directory used by tools like istanbul
24+
coverage
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Other Dependency directories
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# Optional npm cache directory
48+
.npm
49+
50+
# Optional eslint cache
51+
.eslintcache
52+
53+
# Optional REPL history
54+
.node_repl_history
55+
56+
# Output of 'npm pack'
57+
*.tgz
58+
59+
# Yarn Integrity file
60+
.yarn-integrity
61+
62+
# dotenv environment variables file
63+
.env
64+
65+
# next.js build output
66+
.next

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright 2020 Brigham Young University
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,70 @@
1-
# github-action-codedeploy
2-
A GitHub Action for deploying an application via AWS CodeDeploy
1+
# ![BYU logo](https://www.hscripts.com/freeimages/logos/university-logos/byu/byu-logo-clipart-128.gif) github-action-codedeploy
2+
A GitHub Action for deploying an application with AWS CodeDeploy
3+
4+
## Usage
5+
6+
```yaml
7+
on: push
8+
# ...
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
steps:
13+
# ... Initial setup of AWS Creds, etc.
14+
- name: CodeDeploy
15+
uses: byu-oit/github-action-codedeploy@v1
16+
with:
17+
application-name: some-cd-app
18+
deployment-group-name: some-cd-group
19+
appspec-file: some-appspec-file
20+
# ... The rest of your deployment
21+
```
22+
23+
If you are using Terraform to manage your AWS resources, you can add your CodeDeploy resources as outputs. Then you can use `terraform output` to get the values:
24+
25+
```yaml
26+
on: push
27+
# ...
28+
jobs:
29+
deploy:
30+
runs-on: ubuntu-latest
31+
steps:
32+
# ... Initial setup of AWS Creds, Terraform, etc.
33+
- name: 'Get CD App Name'
34+
id: cd-app-name
35+
working-directory: ${{ env.tf_working_dir }}
36+
run: terraform output codedeploy_app_name
37+
38+
- name: 'Get CD Deployment Group Name'
39+
id: cd-group-name
40+
working-directory: ${{ env.tf_working_dir }}
41+
run: terraform output codedeploy_deployment_group_name
42+
43+
- name: 'Get CD Appspec File'
44+
id: cd-appspec-file
45+
working-directory: ${{ env.tf_working_dir }}
46+
run: terraform output codedeploy_appspec_json_file
47+
48+
- name: 'CodeDeploy'
49+
uses: byu-oit/github-action-codedeploy@v1
50+
with:
51+
application-name: ${{ steps.cd-app-name.outputs.stdout }}
52+
deployment-group-name: ${{ steps.cd-group-name.outputs.stdout }}
53+
appspec-file: ${{ steps.cd-appspec-file.outputs.stdout }}
54+
# ... The rest of your deployment
55+
```
56+
57+
## Contributing
58+
Hopefully this is useful to others at BYU. Feel free to ask me some questions about it, but I make no promises about being able to commit time to support it.
59+
60+
### Modifying Source Code
61+
62+
Just run `npm install` locally. There aren't many files here, so hopefully it should be pretty straightforward.
63+
64+
### Cutting new releases
65+
66+
GitHub Actions will run the entry point from the `action.yml`. In our case, that happens to be `/dist/index.js`.
67+
68+
Actions run from GitHub repos. We don't want to check in `node_modules`. Hence, we package the app using `npm run package`.
69+
70+
Then, be sure to create a new GitHub release, following SemVer.

action.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: 'CodeDeploy'
2+
description: 'Create a CodeDeploy Deployment'
3+
inputs:
4+
application-name:
5+
description: 'CodeDeploy Application Name'
6+
required: true
7+
deployment-group-name:
8+
description: 'CodeDeploy Deployment Group Name'
9+
required: true
10+
appspec-file:
11+
description: 'Appspec file'
12+
required: true
13+
#outputs:
14+
# time: # id of output
15+
# description: 'The time we greeted you'
16+
runs:
17+
using: 'node12'
18+
main: 'dist/index.js'

dist/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const core = require('@actions/core');
2+
const fs = require('fs');
3+
const client = require('aws-sdk/clients/codedeploy');
4+
5+
async function run () {
6+
try {
7+
const appName = core.getInput('application-name');
8+
const groupName = core.getInput('deployment-group-name');
9+
const appspecFile = core.getInput('appspec-file');
10+
console.log(`Hello world! ${appName}, ${groupName}, ${appspecFile}`);
11+
12+
const appspecJson = fs.readFileSync(appspecFile, 'utf8');
13+
14+
console.log("1 ", appspecJson);
15+
//
16+
// const cliInputJson = {
17+
// "applicationName": appName,
18+
// "deploymentGroupName": groupName,
19+
// "revision": {
20+
// "revisionType": "AppSpecContent",
21+
// "appSpecContent": {
22+
// "content": JSON.stringify(appspecJson)
23+
// }
24+
// }
25+
// }
26+
//
27+
// console.log("2 ", JSON.stringify(appspecJson));
28+
29+
const codeDeploy = new client();
30+
const deployment = await codeDeploy.createDeployment({
31+
applicationName: appName,
32+
deploymentGroupName: groupName,
33+
revision: {
34+
revisionType: "AppSpecContent",
35+
appSpecContent: {
36+
content: appspecJson
37+
}
38+
}
39+
}).promise();
40+
console.log('deployment', deployment);
41+
await codeDeploy.waitFor('deploymentSuccessful', {deploymentId: deployment.deploymentId}).promise();
42+
43+
// const time = (new Date()).toTimeString();
44+
// core.setOutput("time", time);
45+
// // Get the JSON webhook payload for the event that triggered the workflow
46+
// const payload = JSON.stringify(github.context.payload, undefined, 2)
47+
// console.log(`The event payload: ${payload}`);
48+
process.exit(0);
49+
} catch (error) {
50+
console.error(error);
51+
core.setFailed(error.message);
52+
process.exit(1);
53+
}
54+
}
55+
56+
run();

package-lock.json

Lines changed: 113 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "github-action-codedeploy",
3+
"version": "1.0.0",
4+
"description": "codedeploy github action",
5+
"main": "index.js",
6+
"scripts": {
7+
"package": "ncc build index.js -m -o dist",
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"author": "Scott Hutchings",
11+
"license": "Apache-2.0",
12+
"dependencies": {
13+
"@actions/core": "^1.2.4",
14+
"aws-sdk": "^2.677.0"
15+
},
16+
"devDependencies": {
17+
"@zeit/ncc": "^0.22.3"
18+
}
19+
}

0 commit comments

Comments
 (0)