generated from sfeir-open-source/sfeir-school-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: write first version of this training
Co-authored-by: Thibauld Dujardin<dujardin.t@sfeir.com> Co-authored-by: Romain Lespinasse<lespinasse.r@sfeir.com>
- Loading branch information
1 parent
fc4e2b9
commit d6d2431
Showing
875 changed files
with
26,695 additions
and
43,459 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Contexts Access | ||
description: Show contexts accessible inside an Action | ||
inputs: | ||
value: | ||
description: value | ||
required: false | ||
default: some | ||
runs: | ||
using: composite | ||
steps: | ||
- id: some-step | ||
run: echo "Some step stuff" | ||
shell: bash | ||
- run: | | ||
echo "${{ github.sha }}" | ||
echo "${{ env.ANYTHING }}" | ||
echo "${{ job.container }}" | ||
echo "${{ steps.some-step.conclusion }}" | ||
echo "${{ runner.os }}" | ||
echo "${{ strategy.fail-fast }}" | ||
echo "${{ matrix.value }}" | ||
echo "${{ inputs.value }}" | ||
shell: bash | ||
# Inaccessible contexts | ||
# - jobs | ||
# - secrets | ||
# - needs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: 'Operations' | ||
description: 'Perform operations' | ||
inputs: | ||
input1: | ||
description: 'value that will be use to do math' | ||
required: true | ||
input2: | ||
description: 'value that will be use to do math' | ||
required: true | ||
outputs: | ||
addition: | ||
description: 'The current addition result' | ||
subtraction: | ||
description: 'The current subtraction result' | ||
multiplication: | ||
description: 'The current multiplication result' | ||
runs: | ||
using: 'node16' | ||
main: 'dist/index.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const core = require('@actions/core'); | ||
const { runner } = require("./runner"); | ||
const { add, subtract, multiply } = require("./math"); | ||
|
||
async function run() { | ||
runner(core, add, subtract, multiply); | ||
} | ||
|
||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const core = require('@actions/core'); | ||
const { runner } = require("./runner"); | ||
const { add, subtract, multiply } = require("./math"); | ||
const process = require('process'); | ||
const cp = require('child_process'); | ||
const path = require('path'); | ||
|
||
test('make sure it returns something', async () => { | ||
const core = { | ||
getInput: jest.fn().mockResolvedValue(parseInt(42)), | ||
debug: jest.fn(), | ||
info: jest.fn(), | ||
warning: jest.fn(), | ||
setFailed: jest.fn(), | ||
setOutput: jest.fn() | ||
}; | ||
const math = { | ||
add: jest.fn().mockReturnValue(1) | ||
}; | ||
runner(core, math.add, subtract, multiply) | ||
expect(core.getInput).toHaveBeenCalledTimes(2); | ||
expect(core.debug).toHaveBeenCalledTimes(2); | ||
expect(core.info).toHaveBeenCalledTimes(3); | ||
expect(core.warning).toHaveBeenCalledTimes(1); | ||
expect(core.setOutput).toHaveBeenCalledTimes(3); | ||
expect(core.setFailed).toHaveBeenCalledTimes(0); | ||
expect(math.add).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
describe("simple test", () => { | ||
it('test runs', () => { | ||
process.env['INPUT_INPUT1'] = 9; | ||
process.env['INPUT_INPUT2'] = 5; | ||
|
||
const ip = path.join(__dirname, 'index.js'); | ||
const result = cp.execSync(`node ${ip}`, { env: process.env }).toString(); | ||
expect(result).toContain("::set-output name=addition::14"); | ||
expect(result).toContain("::set-output name=subtraction::4"); | ||
expect(result).toContain("::set-output name=multiplication::45"); | ||
}) | ||
}); | ||
|
||
describe("simple arithmetic", () => { | ||
describe("addition", () => { | ||
test("expect 9 + 5 = 14", () => { | ||
expect(add(9, 5)).toEqual(14); | ||
}); | ||
}); | ||
|
||
describe("subtract", () => { | ||
test("expect 9 - 5 = 4", () => { | ||
expect(subtract(9, 5)).toEqual(4); | ||
}); | ||
}); | ||
|
||
describe("multiply", () => { | ||
test("expect 9 * 5 = 45", () => { | ||
expect(multiply(9, 5)).toEqual(45); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const add = (x, y) => parseInt(x, 10) + parseInt(y, 10); | ||
const subtract = (x, y) => parseInt(x, 10) - parseInt(y, 10); | ||
const multiply = (x, y) => parseInt(x, 10) * parseInt(y, 10); | ||
|
||
module.exports = { | ||
add, | ||
subtract, | ||
multiply, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "operations", | ||
"version": "1.0.0", | ||
"description": "Perform operations", | ||
"main": "index.js", | ||
"scripts": { | ||
"prepare": "ncc build index.js -o dist --source-map", | ||
"test": "jest" | ||
}, | ||
"dependencies": { | ||
"@actions/core": "^1.2.5" | ||
}, | ||
"devDependencies": { | ||
"@vercel/ncc": "^0.31.1", | ||
"jest": "^27.3.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
function runner(core, add, subtract, multiply) { | ||
try { | ||
const input1 = core.getInput('input1'); | ||
const input2 = core.getInput('input2'); | ||
|
||
const start = new Date(); | ||
core.debug('Starting at : ' + start.toTimeString()); | ||
|
||
core.info(`Performing addition of : ${input1} & ${input2} ...`); | ||
const addResult = add(input1, input2); | ||
|
||
core.info(`Performing subtraction of : ${input1} & ${input2} ...`); | ||
const subtractResult = subtract(input1, input2); | ||
|
||
core.info(`Performing multiplication of : ${input1} & ${input2} ...`); | ||
const multiplyResult = multiply(input1, input2); | ||
|
||
const end = new Date(); | ||
core.debug('Ending at : ' + end.toTimeString()); | ||
|
||
core.warning('Delta between startTime & endTime : ' + (end - start)); | ||
|
||
core.setOutput('addition', addResult); | ||
core.setOutput('subtraction', subtractResult); | ||
core.setOutput('multiplication', multiplyResult); | ||
} catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
} | ||
|
||
module.exports = { | ||
runner | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: Runs Reusable Workflow | ||
description: Example of composite action calling a reusable workflow | ||
runs: | ||
using: 'composite' | ||
steps: | ||
- uses: actions/checkout@v3 | ||
# This should failed due to system limitation | ||
- uses: ./.github/workflows/code.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Runs Using Composite | ||
description: Example of composite action | ||
runs: | ||
using: 'composite' | ||
steps: | ||
# Using 'shell: bash' enable the actions to be available for all OS even windows. | ||
# But the script will still need to manage the OS compliance | ||
- run: $GITHUB_ACTION_PATH/setup.sh | ||
shell: bash | ||
if: runner.os == 'windows' | ||
|
||
# Composite action can run another action (composite or note) | ||
- name: Use another action | ||
uses: rlespinasse/github-slug-action@v4 | ||
with: | ||
prefix: CI_ | ||
|
||
# Result of an previous step are directly available (like $CI_GITHUB_REF_SLUG from github-slug-action) | ||
- run: $GITHUB_ACTION_PATH/main.sh | ||
shell: bash | ||
env: | ||
SLUG_REF: $CI_GITHUB_REF_SLUG | ||
|
||
- run: ls | ||
shell: bash | ||
working-directory: . | ||
|
||
- run: $GITHUB_ACTION_PATH/cleanup.sh | ||
shell: bash | ||
if: failure() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env sh | ||
|
||
echo "Cleaning up..." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env sh | ||
|
||
echo "Doing stuff..." "$SLUG_REF" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env sh | ||
|
||
echo "Setting up..." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM debian | ||
|
||
ADD main.sh /usr/local/bin/main.sh | ||
ADD setup.sh /usr/local/bin/setup.sh | ||
ADD cleanup.sh /usr/local/bin/cleanup.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: Runs Using Docker | ||
description: Example of Dockerfile action | ||
runs: | ||
using: 'docker' | ||
image: 'Dockerfile' | ||
# pre/post features will not run if the action is run locally, it's only print a warning | ||
pre-entrypoint: 'setup.sh' | ||
entrypoint: 'main.sh' | ||
post-entrypoint: 'cleanup.sh' | ||
env: | ||
KEY: 'Value' | ||
args: | ||
- 'firstArg' | ||
- 'secondArg' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env sh | ||
|
||
echo "Cleaning up..." "$@" "($KEY)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env sh | ||
|
||
echo "Doing stuff..." "$@" "($KEY)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env sh | ||
|
||
echo "Setting up..." "$@" "($KEY)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: Runs Using Node | ||
description: Example of JavaScript action | ||
runs: | ||
using: 'node16' | ||
main: 'main.js' | ||
# pre/post features will not run if the action is run locally, it's only print a warning | ||
pre: 'setup.js' | ||
pre-if: runner.os == 'Windows' | ||
post: 'cleanup.js' | ||
post-if: failure() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log(`Cleaning up..`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log(`Doing stuff...`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log(`Setting up..`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Summary in composite | ||
description: Example of summary in a composite action | ||
runs: | ||
using: 'composite' | ||
steps: | ||
# the summary can be fill using the actions toolkit | ||
- uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
await core.summary | ||
.addRaw('## Summary from composite action using github script') | ||
.write() | ||
# or fill using $GITHUB_STEP_SUMMARY environment variable | ||
- run: | | ||
echo "## Summary from composite action using echo" >> $GITHUB_STEP_SUMMARY | ||
shell: bash | ||
# Composite action is call from one step, and contains multiple steps. | ||
# Due to limitation, you will not see the '## Summary from composite action using github script' part, | ||
# The composite steps override previous defined summary. | ||
# This will not impacted the other steps of a job from the caller workflow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Testable action | ||
description: Example of a testable action | ||
inputs: | ||
value: | ||
description: value to affect to the output | ||
required: true | ||
outputs: | ||
value: | ||
description: output value | ||
value: '${{ steps.final-output-value.outputs.outputValue }}' | ||
runs: | ||
using: 'composite' | ||
steps: | ||
- run: | | ||
echo "OUTPUT_VALUE=output-${{ inputs.value }}" >> $GITHUB_ENV | ||
shell: bash | ||
if: ${{ inputs.value != '' }} | ||
- run: | | ||
echo "::error ::Value need to be fill" | ||
exit 1 | ||
shell: bash | ||
if: ${{ inputs.value == '' }} | ||
- id: final-output-value | ||
run: echo "::set-output name=outputValue::${{ env.OUTPUT_VALUE }}" | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Run Actions / Code section | ||
on: | ||
push: | ||
workflow_call: # this trigger enable the workflow to be reusable from another workflow, see reuse.yaml file | ||
jobs: | ||
runs-using-actions: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# Run action using the public access {repo}/{path}@{ref} | ||
- uses: sfeir-open-source/sfeir-school-github-action-dev/.github/actions/runs-using-node@main | ||
- uses: sfeir-open-source/sfeir-school-github-action-dev/.github/actions/runs-using-docker@main | ||
- uses: sfeir-open-source/sfeir-school-github-action-dev/.github/actions/runs-using-composite@main | ||
|
||
runs-using-actions-local: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# Run local action by checkout the source and uses it | ||
- uses: actions/checkout@v3 | ||
- uses: ./.github/actions/runs-using-composite | ||
|
||
# For node and docker action, the pre/post features will not run if the action is run locally, it's only print a warning | ||
- uses: ./.github/actions/runs-using-node | ||
- uses: ./.github/actions/runs-using-docker |
Oops, something went wrong.