Skip to content

Commit adb6f74

Browse files
authored
feat: Greet GitHub Actor (#1)
1 parent 649567d commit adb6f74

File tree

16 files changed

+11099
-0
lines changed

16 files changed

+11099
-0
lines changed

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
9+
[*.{js,json,ts,yml}]
10+
indent_style = space
11+
indent_size = 2
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: "Package Action"
2+
3+
on:
4+
push:
5+
branches:
6+
- "release"
7+
8+
jobs:
9+
push-changes:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
with:
14+
ssh-key: "${{ secrets.COMMIT_KEY }}"
15+
- name: Install Javascript dependencies with npm
16+
run: npm install
17+
- name: Package action for distribution
18+
run: npm run package
19+
- name: Push packaged action to branch
20+
uses: EndBug/add-and-commit@v7
21+
with:
22+
add: "dist --force"
23+
default_author: github_actions
24+
message: "build: Package action as `dist` with latest changes"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: "Synchronise To Release Branch"
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
8+
env:
9+
source: ${{ secrets.BRANCHES_SOURCE || 'main' }}
10+
release: ${{ secrets.BRANCHES_RELEASE || 'release' }}
11+
12+
jobs:
13+
update-branch:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
with:
18+
ref: "${{ env.release }}"
19+
fetch-depth: 0
20+
ssh-key: "${{ secrets.COMMIT_KEY }}"
21+
- uses: pr-mpt/actions-merge-branch@v1
22+
with:
23+
from: "origin/${{ env.source }}"

.github/workflows/test.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: "Test Action"
2+
3+
on:
4+
push:
5+
branches:
6+
- "**"
7+
8+
jobs:
9+
test-unit:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- run: npm install
14+
- name: Execute unit tests
15+
run: npm run all
16+
test-integration:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v2
20+
- run: npm install
21+
- run: npm run package
22+
- id: default
23+
uses: ./
24+
- name: Test actor is greeted by default
25+
uses: pr-mpt/actions-assert@v2
26+
with:
27+
assertion: npm://@assertions/is-equal
28+
expected: "Hello, ${{ github.actor }}!"
29+
actual: "${{ steps.default.outputs.greeting }}"
30+
- id: name
31+
uses: ./
32+
with:
33+
name: "Alice T. Ester"
34+
- name: Test name is greeted
35+
uses: pr-mpt/actions-assert@v2
36+
with:
37+
assertion: npm://@assertions/is-equal
38+
expected: "Hello, Alice T. Ester!"
39+
actual: "${{ steps.name.outputs.greeting }}"
40+
- id: empty
41+
uses: ./
42+
with:
43+
name: ""
44+
- name: Test world is greeted when name is empty
45+
uses: pr-mpt/actions-assert@v2
46+
with:
47+
assertion: npm://@assertions/is-equal
48+
expected: "Hello, World!"
49+
actual: "${{ steps.empty.outputs.greeting }}"
50+
51+

.github/workflows/validate-tag.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: "Limit Tags To Distributable Commits"
2+
3+
on:
4+
push:
5+
tags:
6+
- "**"
7+
8+
jobs:
9+
validate-tag:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
with:
14+
ssh-key: "${{ secrets.COMMIT_KEY }}"
15+
- name: Test that the tagged commit includes `dist`
16+
uses: pr-mpt/actions-assert@v2
17+
with:
18+
assertion: npm://@assertions/directory-exists
19+
expected: dist
20+
- if: failure()
21+
name: Delete invalid tag
22+
uses: pr-mpt/actions-delete-tag@v1

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/lib
2+
/node_modules
3+
npm-debug.log*
4+
/dist

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2021 > LIMITED and contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Example Action
2+
3+
**Example Action** is a companion to
4+
[Package GitHub Actions automatically with GitHub Actions][blog-post] which
5+
describes how to automatically package GitHub Actions _using_ GitHub Actions,
6+
as an alternative GitHub's recommended strategy.
7+
8+
## Project Structure
9+
10+
### Workflows
11+
12+
- [x] [`package-action.yml`](.github/workflows/package-action.yml) **Package Action** using `ncc` to create a single `dist`
13+
- [x] [`sync-release-branch.yml`](.github/workflows/sync-release-branch.yml) **Synchronise To Release Branch** on push to `main`
14+
- [x] [`test.yml`](.github/workflows/test.yml) **Test Action** with jest for unit and GitHub Workflow for integration
15+
- [x] [`validate-tag.yml`](.github/workflows/validate-tag.yml) **Limit Tags To Distributable Commits** by removing tags on commits without `dist`
16+
17+
## How To Demo
18+
19+
* Fork the repository
20+
* Create a `release` branch from `main`
21+
* Add a commit key (secret, deploy key)
22+
23+
### Synchronising
24+
25+
* Push changes to `main` and observe `release` is updated with changes
26+
27+
### Packaging
28+
29+
* Push changes to `greeter.ts` on `main` and observe `release` is updated with a new `dist` build
30+
31+
### Tag Validation
32+
33+
* Tag a release on `main` and observe it is removed
34+
* Tag a release on `release` and observe it is persisted
35+
36+
## Greet With Action
37+
38+
```yaml
39+
on: [push]
40+
41+
jobs:
42+
greet-people:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- id: greeting-actor
46+
uses: ./
47+
- name: Greet the user that initiated the workflow run
48+
run: echo {{ steps.greeting-actor.outputs.greeting }} # Hello, shrink!
49+
- id: greeting-person
50+
uses: ./
51+
with:
52+
name: "Alice T. Ester"
53+
- name: Greet the person identified by name
54+
run: echo {{ steps.greeting-person.outputs.greeting }} # Hello, Alice T. Ester!
55+
```
56+
57+
[blog-post]: https://medium.com/prompt/a70b9f7bae4

__tests__/greeter.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Greeter } from "../src/greeter";
2+
3+
describe("greeter", () => {
4+
it("greets user by name", () => {
5+
expect(new Greeter("Hello, {name}!").greet("Sam")).toBe("Hello, Sam!");
6+
});
7+
8+
it("greets world when name is empty", () => {
9+
expect(new Greeter("Hello, {name}!").greet("")).toBe("Hello, World!");
10+
});
11+
});

action.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: "Example Action"
2+
branding:
3+
icon: "loader"
4+
color: "white"
5+
description: "A simple example action that greets someone"
6+
author: "Samuel Ryan <sam@samryan.co.uk>"
7+
inputs:
8+
name:
9+
description: "Name of the person to greet"
10+
default: "${{ github.actor }}"
11+
required: true
12+
outputs:
13+
greeting:
14+
description: "A greeting for the person"
15+
runs:
16+
using: "node12"
17+
main: "dist/index.js"

0 commit comments

Comments
 (0)