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

Custom docker branch (:circleci: way) #4

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/actions-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
on: [push]

jobs:
hello_world_job:
runs-on: [ubuntu-latest] # can't use self-hosted on action because it is public
name: A job to say hello
container: prohfesor/actions_test
steps:

- name: Hello world action step
id: hello
shell: bash
env:
WHO_TO_GREET: 'Transferwise'
DIR: /
run: |
source /entrypoint.sh
greet
out_time
out_other

# Use the output from the `hello` step
- name: Get all outputs
run: |
echo "The random id was ${{ steps.hello.outputs.random-id }}"
echo "The listing was: " && echo "${{ steps.hello.outputs.listing }}"
echo "The time was ${{ steps.hello.outputs.time }}"
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM docker.tw.ee/actions_base

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENV WHO_TO_GREET=World
ENV DIR=/

ENTRYPOINT ["/entrypoint.sh"]
35 changes: 25 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
# actions-test
Different ways to create a custom action.
Example of a custom github action

Here you can find examples of how to create very simple github action, with different approaches available.
## Usage example
```yml
container: prohfesor/actions_test
steps:

This simple action prints out `hello world` (or `!FNAME!`, as set).
Then it takes a directory listing, from the path specified in input vars.
Output vars contain a timestamp, a random number and a result of directory listing.
- name: Hello world action step
id: hello
shell: bash
env:
WHO_TO_GREET: 'Transferwise'
DIR: /
run: |
source /entrypoint.sh
greet
out_time
out_other

## Check branches for detailed examples
- Docker action https://github.com/transferwise/actions-test/tree/docker-action
- Javascript action https://github.com/transferwise/actions-test/tree/javascript-action
- Composite action https://github.com/transferwise/actions-test/tree/composite-action
- Custom docker (:circleci: way) https://github.com/transferwise/actions-test/tree/custom-docker-action
# Use the output from the `hello` step
- name: Get all outputs
run: |
echo "The random id was ${{ steps.hello.outputs.random-id }}"
echo "The listing was: " && echo "${{ steps.hello.outputs.listing }}"
echo "The time was ${{ steps.hello.outputs.time }}"
```

Run examples: https://github.com/transferwise/actions-test/pull/4/checks
22 changes: 22 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh -l

greet() {
echo "Hello ${WHO_TO_GREET}!"
}

out_time() {
time=$(date)
echo "Time is"
echo "${time}"
echo "::set-output name=time::$time"
}

out_other() {
echo "Listing is "
ls -lah $DIR
LISTING=$(ls $DIR)
echo "::set-output name=listing::$LISTING"

echo "Set random"
echo "::set-output name=random-id::$RANDOM"
}