Last active
May 29, 2024 17:41
-
-
Save viniremigio/08bd5fe86a86b842583ec9d458a5be2e to your computer and use it in GitHub Desktop.
GitHub Workflow using local 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
# Must be in the .github/actions/cached-deps folder | |
name: 'Retrieve & Cache Dependencies' | |
description: 'Get the dependencies and caches them' | |
inputs: | |
caching: | |
description: 'Turn on/off caching' | |
required: false | |
default: 'true' | |
runs: | |
using: composite | |
steps: | |
- name: Cache dependencies | |
if: inputs.caching == 'true' | |
id: cache | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/.cache/pypoetry | |
.venv | |
~/.local | |
key: poetry-dependencies-${{ hashFiles('**/poetry.lock') }} | |
- name: Install Poetry | |
if: steps.cache.outputs.cache-hit != 'true' || inputs.caching != 'true' | |
run: | | |
pip3 install poetry==1.8.2 -v | |
poetry install --no-interaction --no-ansi | |
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
name: Deploy Workflow | |
on: | |
workflow_call: | |
inputs: | |
artifact-name: | |
description: Deployable artifact files | |
required: true | |
type: string | |
outputs: | |
result: | |
description: The result of the deployment operation | |
value: ${{ jobs.deploy.outputs.outcome }} | |
jobs: | |
deploy: | |
outputs: | |
outcome: ${{ steps.set-result.outputs.step-result }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: ${{ inputs.artifact-name }} | |
- name: List files | |
run: ls -la | |
- name: Deploy | |
run: echo "Deploying..." | |
- name: Print Outcome | |
id: set-result | |
run: echo "::set-output name=step-result::success" |
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
name: Quality Gate, Build & Deploy Workflow | |
on: | |
pull_request: | |
types: | |
- opened | |
- edited | |
- ready_for_review | |
branches: | |
- main | |
- feat/** | |
- test/** | |
- fix/** | |
push: | |
branches: | |
- main | |
- feat/** | |
- test/** | |
- fix/** | |
workflow_dispatch: | |
env: | |
ENVIRONMENT: development | |
jobs: | |
lint: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get code | |
uses: actions/checkout@v4 | |
- name: Environment | |
run: echo "Environment=${{ env.ENVIRONMENT }} and Secret=${{ secrets.TEST_SECRET }}" | |
- name: Load & Cache Dependencies | |
uses: ./.github/actions/cached-deps # refers to the action.yml | |
with: | |
caching: 'true' | |
- name: Run Lint | |
run: make lint | |
test: | |
needs: [lint] | |
runs-on: ubuntu-latest | |
outputs: | |
test-output: "${{ steps.test_output.outputs.build_output }}" | |
steps: | |
- name: Get code | |
uses: actions/checkout@v4 | |
- name: Load & Cache Dependencies | |
uses: ./.github/actions/cached-deps | |
- name: Run Output | |
id: test_output | |
run: echo "build_output=test_ok" >> "$GITHUB_OUTPUT" | |
- name: Run tests | |
id: run-tests | |
run: poetry run python -m pytest --html=test_report.html | |
- name: Upload test report | |
if: failure() && steps.run-tests.outcome == 'failure' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: test_report | |
path: test_report.html | |
build: | |
needs: [lint, test] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get code | |
uses: actions/checkout@v4 | |
- name: Load & Cache Dependencies | |
uses: ./.github/actions/cached-deps | |
- name: Run Build | |
run: poetry build --format wheel | |
- name: Upload Artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dist-files | |
path: | | |
dist | |
main.py | |
- name: Build Output | |
run: echo "${{ needs.test.outputs.test-output }}" | |
deploy: | |
needs: [build] | |
uses: ./.github/workflows/deploy.yml # refers to some reusable deploy workflow | |
with: | |
artifact-name: dist-files | |
print-deploy-result: | |
needs: [deploy] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Print deploy output | |
run: echo "${{ needs.deploy.outputs.result }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment