Skip to content

Instantly share code, notes, and snippets.

@managedkaos
Created January 15, 2022 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save managedkaos/4035431ef822681aab6efa958439e0ac to your computer and use it in GitHub Desktop.
Save managedkaos/4035431ef822681aab6efa958439e0ac to your computer and use it in GitHub Desktop.

01_04-composite-actions

Use these files to test a composite action.

  1. Create TWO new repos:
    • one to host the composite action
    • one to host the workflow that uses the action
  2. Upload the file action.yml into the root of the compsite action repo.
  3. Upload the following files into the root of the workflow repo:
    main.py
    requirements.txt
    
  4. Edit the file composite-action-workflow.yml to replace the following placeholders with the correct values:
    YOUR_GITHUB_USER_NAME
    YOUR_COMPOSITE_ACTION_REPO_NAME
    
  5. If your username is octocat and the composite repo name is awesome-action, your composite-action-workflow.yml should now include a line as follows:
    uses: octocat/awesome-action@main
    
  6. Upload the file composite-action-workflow.yml into the .github/workflows directory of the composite action repo.
  7. Once the workflow file is commited, the workflow should be triggered by a push event.
  8. Confirm the workflow runs as expected and includes output from the composite action.
name: Standard Python Steps
description: Runs the standard steps for Python
inputs:
PYTHON_VERSION:
description: The version of Python to use
required: true
default: 3.x
RUN_UNIT_TESTS:
description: Set to true to run unit tests
required: false
default: false
outputs:
PROJECT_FILES:
description: "The pattern used to match files in the project"
value: ${{ steps.project_files.outputs.files }}
runs:
using: "composite"
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ inputs.PYTHON_VERSION }}
uses: actions/setup-python@v2
with:
python-version: ${{ inputs.PYTHON_VERSION }}
- name: Install requirements
run: |
pip install -r requirements.txt
pip install flake8
pip install pylint
shell: bash
- name: Identify project files
id: project_files
run: |
if [ -d "./tests" ];
then
echo "::set-output name=files::*.py tests/*.py"
else
echo "::set-output name=files::*.py"
fi
shell: bash
- name: flake8
run: flake8 --ignore=E501,E231 ${{ steps.project_files.outputs.files }}
shell: bash
- name: pylint
run: pylint --errors-only --disable=C0301 --disable=C0326 ${{ steps.project_files.outputs.files }}
shell: bash
- name: unit tests
if: ${{ inputs.RUN_UNIT_TESTS }}
run: python -m unittest --verbose --failfast
shell: bash
name: Use Composite Action
on:
push:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
# REPLACE THE FOLLOWING WITH THE PROPER VALUES
# - YOUR_GITHUB_USER_NAME
# - YOUR_COMPOSITE_ACTION_REPO_NAME
- uses: YOUR_GITHUB_USER_NAME/YOUR_COMPOSITE_ACTION_REPO_NAME@main
with:
PYTHON_VERSION: 3.8
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment