Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Propose a refactor to use Js instead #4

Merged
merged 14 commits into from
May 29, 2024
34 changes: 34 additions & 0 deletions .github/workflows/testAction.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
on:
push:
branches:
- migrateAction

permissions:
id-token: write
contents: read

jobs:
test_action_job:
runs-on: ubuntu-latest
name: Run AWS Eco Runner
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-west-2
role-to-assume: arn:aws:iam::800406105498:role/aws-eco-runner

- name: Execute Action Start
uses: ./
with:
instances_id: '["i-048cc57d9aba24d87"]'
action: "start"

- name: Execute Action Stop
uses: ./
with:
instances_id: '["i-048cc57d9aba24d87"]'
action: "stop"
129 changes: 129 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 NodeSource

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The runner is kept active every 2 days (to not be removed as a Github Runner) an
- name: Start Runner
uses: nodesource/aws-eco-runner@v1
with:
instance_id: $INSTANCE_ID
instance_id: '["i-01", "i-02"]'
action: 'start'
aws_default_region: 'us-west-2'

Expand All @@ -30,7 +30,24 @@ The runner is kept active every 2 days (to not be removed as a Github Runner) an
- name: Stop Runner
uses: nodesource/aws-eco-runner@v1
with:
instance_id: $INSTANCE_ID
instance_id: '["i-01"]'
action: 'stop'
aws_default_region: 'us-west-2'
```

This action requires a minimal permission to start and stop the instance:
This is an example IAM policy, you must adapt it to your needs.

```json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": ["ec2:StartInstances", "ec2:StopInstances"],
"Resource": ["arn:aws:ec2:${REGION}:${ACCOUNT_ID}:instance/${INSTANCE_ID}"]
}
]
}
```
32 changes: 12 additions & 20 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
name: 'aws-eco-runner'
description: 'AWS Eco Runner is a solution designed to optimize the cost of using GitHub Actions runners'
author: 'NodeSource'
name: "aws-eco-runner"
description: "AWS Eco Runner is a solution designed to optimize the cost of using GitHub Actions runners"
author: "NodeSource"

inputs:
instance_id:
description: 'ID of the EC2 instance to start OR the name of the scaling group to scale down'
instances_id:
description: "Array with ID of the EC2 instance to start OR stop"
required: true
action:
description: 'Define if I want to start or stop the runner'
required: true
aws_default_region:
description: 'AWS region to use'
description: "Define if I want to start or stop the runner"
required: true
default: "start"

runs:
using: "composite"
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Start/Stop Runner Instance
shell: bash
run: |
${GITHUB_ACTION_PATH}/instance_start_stop.bash --instance-id=${{ inputs.instance_id }} --action=${{ inputs.action }}
using: "node20"
main: "dist/index.js"
post-if: success()

branding:
icon: 'award'
color: 'green'
icon: "award"
color: "green"
20 changes: 20 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "https://biomejs.dev/schemas/1.7.0/schema.json",
"organizeImports": {
"enabled": true
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"lineWidth": 120
},
"files": {
"ignore": ["dist/*.js"]
},
"linter": {
"enabled": true,
"rules": {
"all": true
}
}
}
Loading