generated from shipyard/github-action-python-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8636d24
Showing
6 changed files
with
91 additions
and
0 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,20 @@ | ||
# .github/workflows/test_action.yaml | ||
name: Test Action | ||
on: [push] | ||
|
||
jobs: | ||
get-num-square: | ||
runs-on: ubuntu-latest | ||
name: Return's the number square | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Fetch num squared | ||
id: get_square | ||
uses: ./ # Uses an action in the root directory | ||
# or use a released Github Action | ||
# uses: shipyard/github-action/[email protected] | ||
with: | ||
num: 11 | ||
- name: Print the square | ||
run: echo "${{ steps.get_square.outputs.num_squared }}" |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Shipyard | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 @@ | ||
# Python Github Action | ||
|
||
Returns square of the number passed via action |
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,31 @@ | ||
# action.yaml | ||
name: 'Custom Github Action' | ||
description: 'A Github Action that takes an input and returns the square of the number' | ||
inputs: | ||
num: | ||
description: 'Enter a number' | ||
required: true | ||
default: "1" | ||
outputs: | ||
num_squared: | ||
description: 'Square of the input' | ||
# need to specify the extra `value` field for `composite` actions | ||
value: ${{ steps.get-square.outputs.num_squared }} | ||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Install Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.10' | ||
- name: Install Dependencies | ||
run: pip install -r requirements.txt | ||
shell: bash | ||
- name: Pass Inputs to Shell | ||
run: | | ||
echo "INPUT_NUM=${{ inputs.num }}" >> $GITHUB_ENV | ||
shell: bash | ||
- name: Fetch the number's square | ||
id: get-square | ||
run: python src/get_num_square.py | ||
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 @@ | ||
pytest |
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,15 @@ | ||
# src/get_num_square.py | ||
import os | ||
|
||
# get the input and convert it to int | ||
num = os.environ.get("INPUT_NUM") | ||
if num: | ||
try: | ||
num = int(num) | ||
except Exception: | ||
exit('ERROR: the INPUT_NUM provided ("{}") is not an integer'.format(num)) | ||
else: | ||
num = 1 | ||
|
||
# to set output, print to shell in following syntax | ||
print(f"::set-output name=num_squared::{num ** 2}") |