Skip to content

Commit bc9a5eb

Browse files
authored
Release/v1 (#2)
* fix: codeowners * chore: added aws sdk * feat: send command action * chore: build * chore: delete test-action job * test command arguments * fix: getMultiline for commands input * chore: mock multiline input * chore: build * fix: setup credentials * test * chore: comment local action * docs: readme * chore: lint * chore: lint * chore: lint
1 parent 606009e commit bc9a5eb

File tree

14 files changed

+123164
-464
lines changed

14 files changed

+123164
-464
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,28 @@ jobs:
4343
- name: Test
4444
id: npm-ci-test
4545
run: npm run ci-test
46-
47-
test-action:
48-
name: GitHub Actions Test
49-
runs-on: ubuntu-latest
50-
51-
steps:
52-
- name: Checkout
53-
id: checkout
54-
uses: actions/checkout@v4
55-
56-
- name: Test Local Action
57-
id: test-action
58-
uses: ./
59-
with:
60-
milliseconds: 1000
61-
62-
- name: Print Output
63-
id: output
64-
run: echo "${{ steps.test-action.outputs.time }}"
46+
# test-action:
47+
# name: GitHub Actions Test
48+
# runs-on: ubuntu-latest
49+
#
50+
# steps:
51+
# - name: Checkout
52+
# id: checkout
53+
# uses: actions/checkout@v4
54+
#
55+
# - name: Set up AWS Credentials
56+
# uses: aws-actions/configure-aws-credentials@v4
57+
# with:
58+
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
59+
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
60+
# aws-region: ${{ secrets.AWS_REGION }}
61+
#
62+
# - name: Test Local Action
63+
# id: test-action
64+
# uses: ./
65+
# with:
66+
# instanceName: zipgo-prod-migrated
67+
# workingDirectory: /home/ubuntu/ubuntu
68+
# commands: |
69+
# echo "hi"
70+
# touch bye

CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Repository CODEOWNERS
22

3-
* @actions/actions-oss-maintainers
3+
* @kyY00n

README.md

Lines changed: 76 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -1,205 +1,101 @@
1-
# Create a JavaScript Action
1+
# SSM Send Command Action for GitHub Actions
22

3-
[![GitHub Super-Linter](https://github.com/actions/javascript-action/actions/workflows/linter.yml/badge.svg)](https://github.com/super-linter/super-linter)
4-
![CI](https://github.com/actions/javascript-action/actions/workflows/ci.yml/badge.svg)
3+
This action sends commands to an EC2 instance via AWS Systems Manager (SSM). You
4+
can use it to execute commands on your EC2 instances directly from your GitHub
5+
Actions workflows.
56

6-
Use this template to bootstrap the creation of a JavaScript action. :rocket:
7+
## Example of Usage
78

8-
This template includes compilation support, tests, a validation workflow,
9-
publishing, and versioning guidance.
9+
### Send Commands to an EC2 Instance
1010

11-
If you are new, there's also a simpler introduction in the
12-
[Hello world JavaScript action repository](https://github.com/actions/hello-world-javascript-action).
11+
Before using this action, make sure to include the following
1312

14-
## Create Your Own Action
15-
16-
To create your own action, you can use this repository as a template! Just
17-
follow the below instructions:
18-
19-
1. Click the **Use this template** button at the top of the repository
20-
1. Select **Create a new repository**
21-
1. Select an owner and name for your new repository
22-
1. Click **Create repository**
23-
1. Clone your new repository
24-
25-
> [!IMPORTANT]
26-
>
27-
> Make sure to remove or update the [`CODEOWNERS`](./CODEOWNERS) file! For
28-
> details on how to use this file, see
29-
> [About code owners](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners).
30-
31-
## Initial Setup
32-
33-
After you've cloned the repository to your local machine or codespace, you'll
34-
need to perform some initial setup steps before you can develop your action.
35-
36-
> [!NOTE]
37-
>
38-
> You'll need to have a reasonably modern version of
39-
> [Node.js](https://nodejs.org) handy. If you are using a version manager like
40-
> [`nodenv`](https://github.com/nodenv/nodenv) or
41-
> [`nvm`](https://github.com/nvm-sh/nvm), you can run `nodenv install` in the
42-
> root of your repository to install the version specified in
43-
> [`package.json`](./package.json). Otherwise, 20.x or later should work!
44-
45-
1. :hammer_and_wrench: Install the dependencies
46-
47-
```bash
48-
npm install
49-
```
50-
51-
1. :building_construction: Package the JavaScript for distribution
13+
```yaml
14+
- name: Configure AWS credentials
15+
uses: aws-actions/configure-aws-credentials@v4
16+
with:
17+
role-to-assume: arn:aws:iam::123456789012:role/my-github-actions-role
18+
aws-region: us-east-1
19+
```
5220
53-
```bash
54-
npm run bundle
55-
```
21+
#### Send commands to an EC2 instance
5622
57-
1. :white_check_mark: Run the tests
23+
```yaml
24+
- name: Send commands to EC2 instance
25+
uses: your-github-username/ssm-send-command-action@v1
26+
with:
27+
instanceName: my-ec2-instance
28+
workingDirectory: /path/to/dir
29+
commands: |
30+
echo "Hello World"
31+
ls -la
32+
```
5833
59-
```bash
60-
$ npm test
34+
## Inputs
6135
62-
PASS ./index.test.js
63-
✓ throws invalid number (3ms)
64-
wait 500 ms (504ms)
65-
test runs (95ms)
36+
- `instanceId` (optional): The ID of the EC2 instance you want to connect to.
37+
- `instanceName` (optional): The name of the EC2 instance you want to connect
38+
to. If both `instanceId` and `instanceName` are provided, `instanceId` takes
39+
precedence.
40+
- `workingDirectory` (required): The working directory where you want to execute
41+
commands.
42+
- `commands` (required): The commands you want to execute on the instance.
6643

67-
...
68-
```
44+
## Outputs
6945

70-
## Update the Action Metadata
46+
- `commandId`: The ID of the executed command.
7147

72-
The [`action.yml`](action.yml) file defines metadata about your action, such as
73-
input(s) and output(s). For details about this file, see
74-
[Metadata syntax for GitHub Actions](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions).
48+
## Credentials
7549

76-
When you copy this repository, update `action.yml` with the name, description,
77-
inputs, and outputs for your action.
50+
This action relies on the
51+
[AWS SDK for JavaScript](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials.html)
52+
to determine AWS credentials and region. Use the
53+
[aws-actions/configure-aws-credentials](https://github.com/aws-actions/configure-aws-credentials)
54+
action to configure the GitHub Actions environment with appropriate AWS
55+
credentials and region.
7856

79-
## Update the Action Code
57+
```yaml
58+
- name: Configure AWS credentials
59+
uses: aws-actions/configure-aws-credentials@v4
60+
with:
61+
role-to-assume: arn:aws:iam::123456789012:role/my-github-actions-role
62+
aws-region: us-east-1
63+
```
8064

81-
The [`src/`](./src/) directory is the heart of your action! This contains the
82-
source code that will be run when your action is invoked. You can replace the
83-
contents of this directory with your own code.
65+
### Required Permissions
8466

85-
There are a few things to keep in mind when writing your action code:
67+
Ensure that the IAM role or user associated with the AWS credentials has
68+
permissions to execute SSM commands.
8669

87-
- Most GitHub Actions toolkit and CI/CD operations are processed asynchronously.
88-
In `main.js`, you will see that the action is run in an `async` function.
70+
#### Example
8971

90-
```javascript
91-
const core = require('@actions/core')
92-
//...
72+
Here’s the example IAM Policy you can use for running this GitHub Action:
9373

94-
async function run() {
95-
try {
96-
//...
97-
} catch (error) {
98-
core.setFailed(error.message)
74+
```json
75+
{
76+
"Version": "2012-10-17",
77+
"Statement": [
78+
{
79+
"Effect": "Allow",
80+
"Action": [
81+
"ec2:DescribeInstances",
82+
"ssm:SendCommand",
83+
"ssm:ListCommandInvocations",
84+
"ssm:DescribeInstanceInformation"
85+
],
86+
"Resource": "*"
9987
}
100-
}
101-
```
102-
103-
For more information about the GitHub Actions toolkit, see the
104-
[documentation](https://github.com/actions/toolkit/blob/main/README.md).
105-
106-
So, what are you waiting for? Go ahead and start customizing your action!
107-
108-
1. Create a new branch
109-
110-
```bash
111-
git checkout -b releases/v1
112-
```
113-
114-
1. Replace the contents of `src/` with your action code
115-
1. Add tests to `__tests__/` for your source code
116-
1. Format, test, and build the action
117-
118-
```bash
119-
npm run all
120-
```
121-
122-
> [!WARNING]
123-
>
124-
> This step is important! It will run [`ncc`](https://github.com/vercel/ncc)
125-
> to build the final JavaScript action code with all dependencies included.
126-
> If you do not run this step, your action will not work correctly when it is
127-
> used in a workflow. This step also includes the `--license` option for
128-
> `ncc`, which will create a license file for all of the production node
129-
> modules used in your project.
130-
131-
1. Commit your changes
132-
133-
```bash
134-
git add .
135-
git commit -m "My first action is ready!"
136-
```
137-
138-
1. Push them to your repository
139-
140-
```bash
141-
git push -u origin releases/v1
142-
```
143-
144-
1. Create a pull request and get feedback on your action
145-
1. Merge the pull request into the `main` branch
146-
147-
Your action is now published! :rocket:
148-
149-
For information about versioning your action, see
150-
[Versioning](https://github.com/actions/toolkit/blob/main/docs/action-versioning.md)
151-
in the GitHub Actions toolkit.
152-
153-
## Validate the Action
154-
155-
You can now validate the action by referencing it in a workflow file. For
156-
example, [`ci.yml`](./.github/workflows/ci.yml) demonstrates how to reference an
157-
action in the same repository.
158-
159-
```yaml
160-
steps:
161-
- name: Checkout
162-
id: checkout
163-
uses: actions/checkout@v3
164-
165-
- name: Test Local Action
166-
id: test-action
167-
uses: ./
168-
with:
169-
milliseconds: 1000
170-
171-
- name: Print Output
172-
id: output
173-
run: echo "${{ steps.test-action.outputs.time }}"
88+
]
89+
}
17490
```
17591

176-
For example workflow runs, check out the
177-
[Actions tab](https://github.com/actions/javascript-action/actions)! :rocket:
178-
179-
## Usage
92+
For details on the required permissions, see the
93+
[AWS documentation on SSM](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-ssm-agent.html).
18094

181-
After testing, you can create version tag(s) that developers can use to
182-
reference different stable versions of your action. For more information, see
183-
[Versioning](https://github.com/actions/toolkit/blob/main/docs/action-versioning.md)
184-
in the GitHub Actions toolkit.
95+
## Troubleshooting
18596

186-
To include the action in a workflow in another repository, you can use the
187-
`uses` syntax with the `@` symbol to reference a specific branch, tag, or commit
188-
hash.
97+
### Command not executing
18998

190-
```yaml
191-
steps:
192-
- name: Checkout
193-
id: checkout
194-
uses: actions/checkout@v4
195-
196-
- name: Run my Action
197-
id: run-action
198-
uses: actions/javascript-action@v1 # Commit with the `v1` tag
199-
with:
200-
milliseconds: 1000
201-
202-
- name: Print Output
203-
id: output
204-
run: echo "${{ steps.run-action.outputs.time }}"
205-
```
99+
- Ensure that the `workingDirectory` exists on the instance and that you have
100+
proper permissions.
101+
- Verify that the `commands` input is correctly formatted.

0 commit comments

Comments
 (0)