Skip to content

Commit

Permalink
Update for GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Omicron7 committed Apr 11, 2022
1 parent f02c892 commit 9f3b320
Show file tree
Hide file tree
Showing 14 changed files with 4,857 additions and 6,704 deletions.
5 changes: 5 additions & 0 deletions .env.example → .env
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ LOG_LEVEL=debug

# Go to https://smee.io/new set this to the URL that you are redirected to.
WEBHOOK_PROXY_URL=

ROLLBAR_ACCESS_TOKEN=
PRIVATE_KEY=
DISABLE_WEBHOOK_EVENT_CHECK=
NODE_ENV=
16 changes: 16 additions & 0 deletions .github/workflows/deploy-serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Deploy Serverless Functions

on:
push:
branches:
# Automatically deploy master and staging. Additional branches may be added.
- master
- staging
workflow_dispatch:
# Allows manual build and deploy of any branch/ref

jobs:
# Deploy Serverless functions
deploy:
name: Deploy
uses: CruGlobal/.github/.github/workflows/deploy-serverless.yml@v1
19 changes: 19 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Node.js CI

on:
push:
branches: [ master, staging ]
pull_request:
branches: [ master ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
cache: 'yarn'
- run: yarn install --frozen-lockfile
- run: yarn test
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ node_modules
npm-debug.log
*.pem
!mock-cert.pem
.env
package-lock.json
coverage
.idea

# dotenv environment variables file
!.env
.env

# Serverless directories
.serverless
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nodejs 12.18.0
nodejs 16.14.2
4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

7 changes: 0 additions & 7 deletions Jenkinsfile

This file was deleted.

2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
'@babel/preset-env',
{
targets: {
node: '12'
node: '16'
}
}
],
Expand Down
9 changes: 9 additions & 0 deletions env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This file is used by serverless to load environment from .env, and to set environment fields in functions
module.exports = () => {
const { parsed } = require('dotenv').config()
const env = {}
for (const [key, value] of Object.entries(parsed)) {
env[key] = process.env[key] || value
}
return env
}
49 changes: 25 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"private": true,
"description": "A Probot app for merging branches into staging",
"author": "Spencer Oberstadt <[email protected]>",
"author": "Spencer Oberstadt",
"license": "ISC",
"repository": "https://github.com/CruGlobal/github-merge-bot.git",
"homepage": "https://github.com/CruGlobal/github-merge-bot",
Expand All @@ -30,33 +30,34 @@
"source-map-support": "^0.5.19"
},
"devDependencies": {
"@babel/preset-env": "^7.11.0",
"@babel/preset-typescript": "^7.10.4",
"@types/jest": "^25.1.0",
"@babel/core": "^7.17.9",
"@babel/preset-env": "^7.16.11",
"@babel/preset-typescript": "^7.16.7",
"@types/jest": "^27.4.1",
"@types/nock": "^11.1.0",
"@types/node": "^12.12.0",
"@typescript-eslint/parser": "^2.4.0",
"babel-loader": "^8.1.0",
"babel-plugin-source-map-support": "^2.1.2",
"dotenv": "^8.2.0",
"@types/node": "^17.0.23",
"@typescript-eslint/parser": "^5.19.0",
"babel-loader": "^8.2.4",
"babel-plugin-source-map-support": "^2.1.3",
"dotenv": "^16.0.0",
"eslint-plugin-typescript": "^0.14.0",
"jest": "^24.9.0",
"nock": "^11.4.0",
"nodemon": "^2.0.0",
"rollbar-sourcemap-webpack-plugin": "^2.5.1",
"serverless": "^1.44.1",
"serverless-offline": "^6.4.0",
"serverless-webpack": "^5.3.1",
"smee-client": "^1.1.0",
"standard": "^14.3.1",
"ts-jest": "^25.1.0",
"typescript": "^3.6.4",
"webpack": "^4.2.0",
"webpack-cli": "^3.3.11",
"webpack-node-externals": "^1.6.0"
"jest": "^27.5.1",
"nock": "^13.2.4",
"nodemon": "^2.0.15",
"rollbar-sourcemap-webpack-plugin": "^3.3.0",
"serverless": "^3.12.0",
"serverless-offline": "^8.5.0",
"serverless-webpack": "^5.7.0",
"smee-client": "^1.2.2",
"standard": "^16.0.4",
"ts-jest": "^27.1.4",
"typescript": "^4.6.3",
"webpack": "^5.72.0",
"webpack-cli": "^4.9.2",
"webpack-node-externals": "^3.0.0"
},
"engines": {
"node": ">= 12.18.0",
"node": ">= 16.14.0",
"npm": ">= 4.0.0"
},
"standard": {
Expand Down
52 changes: 29 additions & 23 deletions serverless.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,61 @@
service: github-merge-bot
frameworkVersion: '3'
configValidationMode: error
plugins:
- serverless-webpack
- serverless-offline

provider:
name: aws
stage: ${env:ENVIRONMENT}
runtime: nodejs12.x
region: us-east-1
vpc:
securityGroupIds:
- ${file(${env:ECS_CONFIG}/bin/vars.yml):us-east-1.webapp_elb_sg}
subnetIds: ${file(${env:ECS_CONFIG}/bin/vars.yml):us-east-1.prod_apps_1_all}
- sg-888294ed
subnetIds:
- subnet-f2c2dfda # us-east-1a
- subnet-1508db62 # us-east-1b
- subnet-3fd94266 # us-east-1c
stackTags:
Name: ${env:PROJECT_NAME}-${self:custom.environmentMap.${env:ENVIRONMENT}}
owner: [email protected]
application: ${env:PROJECT_NAME}
env: ${self:custom.environmentMap.${env:ENVIRONMENT}}
managed_by: serverless-framework
function: lambda
environment: ${file(serverless/environment.js)}

functions:
mergebot:
handler: src/handlers.probot
memorySize: 192
timeout: 60
events:
- http:
path: /bot
method: POST
layers:
- arn:aws:lambda:us-east-1:072686360478:layer:node-16_14_2:1
environment: ${file(env.js)}

package:
individually: true
exclude:
- .git/**
- test/**
- '**/*.test.js'
- .deployment/**

plugins:
- serverless-webpack
- serverless-offline
patterns:
- '!.webpack/**'
- '!test/**'
- '!**/*.test.js'
- '!.deployment/**'

custom:
webpack:
webpackConfig: ./webpack.config.js
includeModules: true
packager: yarn
excludeFiles: '**/*.test.js'
excludeRegex: \.ts|test|\.map
environmentMap:
production: prod
staging: stage
development: dev
lab: lab
serverless-offline:
httpPort: 4000

functions:
mergebot:
handler: src/handlers.probot
memorySize: 192
timeout: 60
events:
- http:
path: /bot
method: POST
15 changes: 0 additions & 15 deletions serverless/environment.js

This file was deleted.

80 changes: 45 additions & 35 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,50 @@ const webpack = require('webpack')
const slsw = require('serverless-webpack')
const nodeExternals = require('webpack-node-externals')
const RollbarSourceMapPlugin = require('rollbar-sourcemap-webpack-plugin')
const sourcemapVersion = require('child_process').execSync('git rev-parse --short HEAD').toString().trim()
const childProcess = require('child_process')

module.exports = {
entry: slsw.lib.entries,
target: 'node',
devtool: 'source-map',
externals: [nodeExternals()],
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
performance: {
hints: false
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx']
},
module: {
rules: [
{
// Include ts, tsx, js, and jsx files.
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: [
'babel-loader'
]
}
]
},
plugins: [
new webpack.EnvironmentPlugin({
SOURCEMAP_VERSION: sourcemapVersion
}),
new RollbarSourceMapPlugin({
accessToken: process.env.ROLLBAR_ACCESS_TOKEN,
publicPath: '/var/task',
version: sourcemapVersion
})
]
function git (command) {
return childProcess.execSync(`git ${command}`, { encoding: 'utf8' }).trim()
}

module.exports = (async () => {
const version = git('rev-parse --short HEAD')
return {
entry: slsw.lib.entries,
target: 'node',
devtool: 'hidden-source-map',
externals: [nodeExternals()],
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
performance: {
hints: false
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx']
},
module: {
rules: [
{
// Include ts, tsx, js, and jsx files.
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: [
'babel-loader'
]
}
]
},
plugins: [
new webpack.EnvironmentPlugin({
SOURCEMAP_VERSION: version
}),
process.env.CI
? new RollbarSourceMapPlugin({
accessToken: process.env.ROLLBAR_ACCESS_TOKEN,
ignoreErrors: true,
publicPath: '/var/task',
version: version
})
: false
].filter(Boolean)
}
})()
Loading

0 comments on commit 9f3b320

Please sign in to comment.