From cafcaab432fec3b26e39338bf836d6d383d5e57f Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Sun, 1 Sep 2024 17:48:55 -0400 Subject: [PATCH] Initial commit --- .github/workflows/branch.yaml | 24 +++++++++++++++++++ .github/workflows/main.yaml | 22 +++++++++++++++++ README.md | 37 ++++++++++++++++++++++++++++ action.yaml | 45 +++++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 .github/workflows/branch.yaml create mode 100644 .github/workflows/main.yaml create mode 100644 README.md create mode 100644 action.yaml diff --git a/.github/workflows/branch.yaml b/.github/workflows/branch.yaml new file mode 100644 index 0000000..ab71c26 --- /dev/null +++ b/.github/workflows/branch.yaml @@ -0,0 +1,24 @@ +name: Branch + +on: + workflow_dispatch: + push: + branches: + - '*' + branches-ignore: + - 'main' + +jobs: + build: + runs-on: ubuntu-latest + permissions: + id-token: write + contents: read + + steps: + - name: Action Lint + id: action-lint + uses: raven-actions/actionlint@v2 + with: + files: 'action.yml' + pyflakes: false \ No newline at end of file diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..698f20a --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,22 @@ +name: Main + +on: + workflow_dispatch: + push: + branches: + - 'main' + +jobs: + build: + runs-on: ubuntu-latest + permissions: + id-token: write + contents: read + + steps: + - name: Action Lint + id: action-lint + uses: raven-actions/actionlint@v2 + with: + files: 'action.yml' + pyflakes: false \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0c75fce --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# gha-setup-python +This GitHub Action sets up a Python environment for use in workflows. + +_*NOTE: This workflow is opinionated and meets the needs of its author. It is provided publicly as a reference for others to use and modify as needed.*_ + +This action will perform the following actions: +* Install Python +* Install Pipenv +* Generate Pipfile.lock if does not exist (only to be used in that run) +* Install dependencies + +## Usage +To use this action, add the following step to your workflow: + +```yaml +steps: + - name: Checkout code + uses: serverlessopsio/gha-setup-workspace@v1 + + - name: Setup Python enviornment + uses: serverlessopsio/gha-setup-python@v1 +``` + +## Inputs +* python-version (_optional_): The version of Python to use. This action uses the version resolution employed by [actions/setup-python](https://github.com/actions/setup-python) + +## Outputs +* python-version: he installed Python or PyPy version. Useful when given a version range as input. +* cache-hit: A boolean value to indicate a cache entry was found +* python-path: The absolute path to the Python or PyPy executable. + +## Contributing +Contributions are welcome! Please open an issue or submit a pull request for any changes. + +## Contact +For any questions or support, please open an issue in this repository. + diff --git a/action.yaml b/action.yaml new file mode 100644 index 0000000..88f4d7d --- /dev/null +++ b/action.yaml @@ -0,0 +1,45 @@ + +name: setup-python +description: Installs Python and project dependencies + +inputs: + python_version: + description: Python version + +runs: + using: composite + + steps: + - name: Setup Python + id: install-python + uses: actions/setup-python@v4 + with: + python-version: '${{ inputs.python_version }}' + cache: pipenv + + - name: Install pipenv + id: install-pipenv + shell: bash + run: pip install --user --upgrade pipenv + + # This is to ensure that all jobs in a workflow will resolve the same dependencies + - name: Check Pipfile.lock + id: check-pipfile-lock + shell: bash + run: | + if [ -f Pipfile.lock ]; \ + then \ + echo "has-lock=true" >> $GITHUB_OUTPUT; \ + else \ + echo "has-lock=false" >> $GITHUB_OUTPUT; \ + fi + + - name: Install dependencies + id: install-python-deps + shell: bash + run: pipenv install --dev + +outputs: + python-version: ${{ steps.install-python.outputs.python-version }} + python-path: ${{ steps.install-python.outputs.python-path }} + cache-hit: ${{ steps.install-python.outputs.cache-hit }} \ No newline at end of file