From 68d3eaebc653d84d88b2d97838060f5696713308 Mon Sep 17 00:00:00 2001 From: Steven Leong Date: Thu, 16 Jan 2025 14:39:24 +0800 Subject: [PATCH 1/9] Added a workflow file in local branch --- .github/workflows/DevelopInBranch.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/workflows/DevelopInBranch.yml diff --git a/.github/workflows/DevelopInBranch.yml b/.github/workflows/DevelopInBranch.yml new file mode 100644 index 0000000..21c584b --- /dev/null +++ b/.github/workflows/DevelopInBranch.yml @@ -0,0 +1,12 @@ +# workflow to show how to develop workflows in branches +name: Develop in a branch +on: [pull_request, workflow_dispatch] + +jobs: + job1: + runs-on: ubuntu-latest + steps: + - run: | + echo "Workflow triggered in branch '${{ github.ref }}'." + echo "Workflow triggered by event '${{ github.event_name }}'." + echo "Workflow triggered by actor '${{ github.actor }}''." \ No newline at end of file From 56945201df5f84f8a821da825feeedb64b0e6a83 Mon Sep 17 00:00:00 2001 From: Steven Leong Date: Thu, 16 Jan 2025 14:54:16 +0800 Subject: [PATCH 2/9] Added a workflow file in local branch --- .github/workflows/DevelopInBranch.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/DevelopInBranch.yml b/.github/workflows/DevelopInBranch.yml index 21c584b..80f00ed 100644 --- a/.github/workflows/DevelopInBranch.yml +++ b/.github/workflows/DevelopInBranch.yml @@ -5,8 +5,13 @@ on: [pull_request, workflow_dispatch] jobs: job1: runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write steps: - run: | echo "Workflow triggered in branch '${{ github.ref }}'." echo "Workflow triggered by event '${{ github.event_name }}'." - echo "Workflow triggered by actor '${{ github.actor }}''." \ No newline at end of file + echo "Workflow triggered by actor '${{ github.actor }}''." + - uses: actions/checkout@v4.2.2 + - uses: devops-actions/actionlint@v0.1.3 \ No newline at end of file From ca2c34d30d7c99e0800a7846e1dc513cb0236f33 Mon Sep 17 00:00:00 2001 From: Steven Leong Date: Thu, 16 Jan 2025 15:03:51 +0800 Subject: [PATCH 3/9] Added malicious code --- .github/workflows/DevelopInBranch.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/DevelopInBranch.yml b/.github/workflows/DevelopInBranch.yml index 80f00ed..d9ca26a 100644 --- a/.github/workflows/DevelopInBranch.yml +++ b/.github/workflows/DevelopInBranch.yml @@ -14,4 +14,5 @@ jobs: echo "Workflow triggered by event '${{ github.event_name }}'." echo "Workflow triggered by actor '${{ github.actor }}''." - uses: actions/checkout@v4.2.2 - - uses: devops-actions/actionlint@v0.1.3 \ No newline at end of file + - uses: devops-actions/actionlint@v0.1.3 + - run: echo "${{ github.event.pull_request.title }}" \ No newline at end of file From 19f180aee20ddffcc81ada9ed759378e3b70925c Mon Sep 17 00:00:00 2001 From: Steven Leong Date: Thu, 16 Jan 2025 15:07:01 +0800 Subject: [PATCH 4/9] Added PR Title --- .github/workflows/DevelopInBranch.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/DevelopInBranch.yml b/.github/workflows/DevelopInBranch.yml index d9ca26a..e43bc87 100644 --- a/.github/workflows/DevelopInBranch.yml +++ b/.github/workflows/DevelopInBranch.yml @@ -15,4 +15,4 @@ jobs: echo "Workflow triggered by actor '${{ github.actor }}''." - uses: actions/checkout@v4.2.2 - uses: devops-actions/actionlint@v0.1.3 - - run: echo "${{ github.event.pull_request.title }}" \ No newline at end of file + - run: echo "PR title is '${{ github.event.pull_request.title }}'." \ No newline at end of file From d7f8d4afcdf836aa99676d8724a13507f162d5eb Mon Sep 17 00:00:00 2001 From: Steven Leong Date: Thu, 16 Jan 2025 15:10:54 +0800 Subject: [PATCH 5/9] Added messages to the log --- .github/workflows/DevelopInBranch.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/DevelopInBranch.yml b/.github/workflows/DevelopInBranch.yml index e43bc87..0c4435c 100644 --- a/.github/workflows/DevelopInBranch.yml +++ b/.github/workflows/DevelopInBranch.yml @@ -9,10 +9,15 @@ jobs: contents: read pull-requests: write steps: + # - run: | + # echo "Workflow triggered in branch '${{ github.ref }}'." + # echo "Workflow triggered by event '${{ github.event_name }}'." + # echo "Workflow triggered by actor '${{ github.actor }}''." + # - uses: actions/checkout@v4.2.2 + # - uses: devops-actions/actionlint@v0.1.3 + # - run: echo "PR title is '${{ github.event.pull_request.title }}'." - run: | - echo "Workflow triggered in branch '${{ github.ref }}'." - echo "Workflow triggered by event '${{ github.event_name }}'." - echo "Workflow triggered by actor '${{ github.actor }}''." - - uses: actions/checkout@v4.2.2 - - uses: devops-actions/actionlint@v0.1.3 - - run: echo "PR title is '${{ github.event.pull_request.title }}'." \ No newline at end of file + echo "::debug::This is a debug message." + echo "::notice::This is a notice message." + echo "::warning::This is a warning message." + echo "::error::This is an error message." \ No newline at end of file From 02f671d483a536c86aeea711a890acb2ac42f417 Mon Sep 17 00:00:00 2001 From: Steven Leong Date: Thu, 16 Jan 2025 15:24:46 +0800 Subject: [PATCH 6/9] Added messages to the log --- .github/workflows/DevelopInBranch.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/DevelopInBranch.yml b/.github/workflows/DevelopInBranch.yml index 0c4435c..f48823b 100644 --- a/.github/workflows/DevelopInBranch.yml +++ b/.github/workflows/DevelopInBranch.yml @@ -9,10 +9,10 @@ jobs: contents: read pull-requests: write steps: - # - run: | - # echo "Workflow triggered in branch '${{ github.ref }}'." - # echo "Workflow triggered by event '${{ github.event_name }}'." - # echo "Workflow triggered by actor '${{ github.actor }}''." + - run: | + echo "Workflow triggered in branch '${{ github.ref }}'." + echo "Workflow triggered by event '${{ github.event_name }}'." + echo "Workflow triggered by actor '${{ github.actor }}''." # - uses: actions/checkout@v4.2.2 # - uses: devops-actions/actionlint@v0.1.3 # - run: echo "PR title is '${{ github.event.pull_request.title }}'." @@ -20,4 +20,8 @@ jobs: echo "::debug::This is a debug message." echo "::notice::This is a notice message." echo "::warning::This is a warning message." - echo "::error::This is an error message." \ No newline at end of file + echo "::error::This is an error message." + - run: | + echo "::notice file=.github/workflows/DevelopInBranch.yml,line=19,col=11,endColumn=51::There is a debug message that is not always visible!" + echo "::warning file=.github/workflows/DevelopInBranch.yml,line=19,endline=21::A lot of messages" + echo "::error title=Script Injection,file=.github/workflows/DevelopInBranch.yml,line=13,col=37,endColumn=68::Potential script injection" \ No newline at end of file From d3dc7fb32a80748f4d69f07ac36e368eaf911fed Mon Sep 17 00:00:00 2001 From: Steven Leong Date: Thu, 16 Jan 2025 15:59:08 +0800 Subject: [PATCH 7/9] Added Continuous Integration --- .github/workflows/ci.yml | 18 ++++++++++++++++++ Dockerfile | 12 ++++++++++++ action.yml | 15 +++++++++++++++ entrypoint.sh | 5 +++++ 4 files changed, 50 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 Dockerfile create mode 100644 action.yml create mode 100644 entrypoint.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4aa1667 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,18 @@ +name: Action CI +on: [push] + +jobs: + ci: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.2.2 + - name: Run my own container action + id: my-action + uses: ./ + with: + who-to-greet: '@howsen82' + - name: Test the container + if: ${{ steps.my-action.outputs.answer != 42 }} + run: | + echo "::error file=entrypoint.sh,line=4,title=Error in container::The answer was not expected" + exit 1 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..262fef3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +# Container image that runs your code +# FROM alpine:latest +# CMD echo "Hello World" +FROM alpine:3.21 + +COPY entrypoint.sh /entrypoint.sh + +RUN chmod +x entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] + +# docker run $(docker build -q .) \ No newline at end of file diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..9d309aa --- /dev/null +++ b/action.yml @@ -0,0 +1,15 @@ +name: 'Docker Action Recipe' +description: 'Greet someone' +inputs: + who-to-greet: + description: 'Who to greet' + required: true + default: 'World' +outputs: + answer: + description: 'The answer to everything (always 42)' +runs: + using: 'docker' + image: 'Dockerfile' + args: + - ${{ inputs.who-to-greet }} \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..bb43cd6 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/sh -l +echo "Hello $@" +echo "answer=42" >> $GITHUB_OUTPUT +echo "### Hello $@! :rocket:" >> $GITHUB_STEP_SUMMARY +echo "

The answer from Deep Thought is 42 :robot:

" >> $GITHUB_STEP_SUMMARY \ No newline at end of file From 2ae27c91182831e3e98ce38e833291d638053115 Mon Sep 17 00:00:00 2001 From: Steven Leong Date: Thu, 16 Jan 2025 16:02:58 +0800 Subject: [PATCH 8/9] Fail CI build --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index bb43cd6..213549d 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,5 +1,5 @@ #!/bin/sh -l echo "Hello $@" -echo "answer=42" >> $GITHUB_OUTPUT +echo "answer=7" >> $GITHUB_OUTPUT echo "### Hello $@! :rocket:" >> $GITHUB_STEP_SUMMARY echo "

The answer from Deep Thought is 42 :robot:

" >> $GITHUB_STEP_SUMMARY \ No newline at end of file From 0ea92abcbb6192f1c0ba16502b6d81af8c1692dd Mon Sep 17 00:00:00 2001 From: Steven Leong Date: Thu, 16 Jan 2025 17:21:46 +0800 Subject: [PATCH 9/9] Added branding and author information --- .env | 2 ++ .github/workflows/ci.yml | 8 +++++- 03. Building GitHub Actions.md | 2 +- README.md | 47 ++++++++++++++++++++++++++++++++++ action.yml | 8 ++++++ 5 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 .env create mode 100644 README.md diff --git a/.env b/.env new file mode 100644 index 0000000..bad1ef2 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +echo "{name}={value}" >> "$GITHUB_OUTPUT" +echo "{environment_variable_name}={value}" >> "$GITHUB_ENV" \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4aa1667..5a85067 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,4 +15,10 @@ jobs: if: ${{ steps.my-action.outputs.answer != 42 }} run: | echo "::error file=entrypoint.sh,line=4,title=Error in container::The answer was not expected" - exit 1 \ No newline at end of file + exit 1 + - name: Set the value + id: step_one + run: | + echo "action_state=yellow" >> "$GITHUB_ENV" + - run: | + echo "${{ env.action_state }}" # This will output 'yellow' \ No newline at end of file diff --git a/03. Building GitHub Actions.md b/03. Building GitHub Actions.md index ea01b7b..e7f8131 100644 --- a/03. Building GitHub Actions.md +++ b/03. Building GitHub Actions.md @@ -633,7 +633,7 @@ I haven’t included a recipe for adjusting the unit tests in this book as this npm run bundle git add . git commit -m "Fail CI build" - git push –set-upstream origin fail-ci-build + git push --set-upstream origin fail-ci-build gh pr create --fill ``` diff --git a/README.md b/README.md new file mode 100644 index 0000000..44a6b3d --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# DockerActionRecipe + +A Docker container actions that handles input and output writes a job summary. + +## Inputs + +## `who-to-greet` + +**Required** The name of the person to greet. Default `"World"`. + +## Outputs + +## `answer` + +The answer to the ultimate question of life, the universe, and everything. + +## Usage + +```yaml +- uses: howsen82/DockerActionRecipe@v1.0 + with: + # Required: the person to greet with the action + # Default: World + who-to-greet: '' +``` + +## Examples + +### Simple example + +```yaml +- uses: howsen82/DockerActionRecipe@v1.0 + with: + who-to-greet: 'Steven Leong' +``` + +### Example that uses the output parameter + +```yaml +- uses: howsen82/DockerActionRecipe@v1.0 + id: my-action + with: + who-to-greet: 'Steven Leong' + +- name: Output the answer + run: echo "The answer is '${{ steps.my-action.outputs.answer }}'" +``` \ No newline at end of file diff --git a/action.yml b/action.yml index 9d309aa..58584dc 100644 --- a/action.yml +++ b/action.yml @@ -1,13 +1,21 @@ name: 'Docker Action Recipe' description: 'Greet someone' + +branding: + icon: bell + color: purple +author: 'Steven Leong' + inputs: who-to-greet: description: 'Who to greet' required: true default: 'World' + outputs: answer: description: 'The answer to everything (always 42)' + runs: using: 'docker' image: 'Dockerfile'