Skip to content

Commit

Permalink
Add: Add a new action to setup Python and pontos in a virtualenv
Browse files Browse the repository at this point in the history
We have several actions and workflows that use the latest release of
pontos under the hood. Therefore unify the setup and installation of
pontos in a single action. This allows reusing the virtual environment
and caching. Therefore it will result in faster action runs.
  • Loading branch information
bjoernricks committed May 4, 2023
1 parent 853ed4f commit 9802104
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 112 deletions.
33 changes: 4 additions & 29 deletions admin-bypass/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,9 @@ branding:
runs:
using: "composite"
steps:
- name: Set up Python
uses: actions/setup-python@v4
id: python
with:
python-version: "3.10"
- name: Virtual Environment
- name: Set up Python and pontos
id: virtualenv
run: |
echo "path=${{ github.action_path }}/${{ github.action }}-venv" >> $GITHUB_OUTPUT
echo "name=${{ github.action }}-venv" >> $GITHUB_OUTPUT
shell: bash
- name: Cache Virtual Environment
id: cache-virtualenv
uses: actions/cache@v3
with:
key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ steps.virtualenv.outputs.name }}
path: ${{ steps.virtualenv.outputs.path }}
- name: Create virtual environment
if: ${{ steps.cache-virtualenv.outputs.cache-hit != 'true' }}
run: |
python -m venv ${{ steps.virtualenv.outputs.path }}
shell: bash
- name: Install pontos
run: |
source ${{ steps.virtualenv.outputs.path }}/bin/activate
python -m pip install --upgrade pip
python -m pip install --upgrade pontos
wget https://github.com/greenbone/pontos/raw/main/scripts/github/enforce-admins.py -O ~/enforce-admins.py
shell: bash
uses: greenbone/actions/setup-pontos@v2
- name: allow/not allow bypass?
run: |
if [[ "${{inputs.allow}}" == "true" ]];
Expand All @@ -67,7 +41,8 @@ runs:
# in case of blubber input let the branch be unlocked!
- name: Prepare release and store the version
run: |
source ${{ steps.virtualenv.outputs.path }}/bin/activate
source ${{ steps.virtualenv.outputs.activate }}
wget https://github.com/greenbone/pontos/raw/main/scripts/github/enforce-admins.py -O ~/enforce-admins.py
pontos-github-script ~/enforce-admins.py ${{ inputs.repository }} ${{ inputs.branch }} ${{ env.ALLOW_OPT }}
shell: bash
env:
Expand Down
31 changes: 4 additions & 27 deletions check-version/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,14 @@ runs:
using: "composite"
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v4
id: python
with:
python-version: ${{ inputs.python-version}}
- name: Virtual Environment
- name: Set up Python ${{ inputs.python-version }} and pontos
uses: actions/setup-pontos@v2
id: virtualenv
run: |
echo "path=${{ github.action_path }}/${{ github.action }}-venv" >> $GITHUB_OUTPUT
echo "name=${{ github.action }}-venv" >> $GITHUB_OUTPUT
shell: bash
- name: Cache Virtual Environment
id: cache-virtualenv
uses: actions/cache@v3
with:
key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ steps.virtualenv.outputs.name }}
path: ${{ steps.virtualenv.outputs.path }}
- name: Create virtual environment
if: ${{ steps.cache-virtualenv.outputs.cache-hit != 'true' }}
run: |
python -m venv ${{ steps.virtualenv.outputs.path }}
shell: bash
- name: Install pontos
run: |
source ${{ steps.virtualenv.outputs.path }}/bin/activate
python -m pip install -U pip
python -m pip install pontos
shell: bash
python-version: ${{ inputs.python-version}}
- name: Check version information
run: |
source ${{ steps.virtualenv.outputs.path }}/bin/activate
source ${{ steps.virtualenv.outputs.activate }}
python -m pontos.version verify current
shell: bash
working-directory: ${{ inputs.working-directory }}
33 changes: 4 additions & 29 deletions lock-branch/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,9 @@ branding:
runs:
using: "composite"
steps:
- name: Set up Python
uses: actions/setup-python@v4
id: python
with:
python-version: "3.10"
- name: Virtual Environment
- name: Set up Python and pontos
id: virtualenv
run: |
echo "path=${{ github.action_path }}/${{ github.action }}-venv" >> $GITHUB_OUTPUT
echo "name=${{ github.action }}-venv" >> $GITHUB_OUTPUT
shell: bash
- name: Cache Virtual Environment
id: cache-virtualenv
uses: actions/cache@v3
with:
key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ steps.virtualenv.outputs.name }}
path: ${{ steps.virtualenv.outputs.path }}
- name: Create virtual environment
if: ${{ steps.cache-virtualenv.outputs.cache-hit != 'true' }}
run: |
python -m venv ${{ steps.virtualenv.outputs.path }}
shell: bash
- name: Install pontos
run: |
source ${{ steps.virtualenv.outputs.path }}/bin/activate
python -m pip install --upgrade pip
python -m pip install --upgrade pontos
wget https://github.com/greenbone/pontos/raw/main/scripts/github/lock-branch.py -O ~/lock-branch.py
shell: bash
uses: greenbone/actions/setup-pontos@v2
- name: lock/unlock?
run: |
if [[ "${{inputs.lock}}" == "true" ]];
Expand All @@ -70,7 +44,8 @@ runs:
# in case of blubber input let the branch be unlocked!
- name: Prepare release and store the version
run: |
source ${{ steps.virtualenv.outputs.path }}/bin/activate
source ${{ steps.virtualenv.outputs.activate }}
wget https://github.com/greenbone/pontos/raw/main/scripts/github/lock-branch.py -O ~/lock-branch.py
pontos-github-script ~/lock-branch.py ${{ inputs.repository }} ${{ inputs.branch }} ${{ env.LOCK_OPT }}
shell: bash
env:
Expand Down
34 changes: 34 additions & 0 deletions setup-pontos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Setup Pontos Action

GitHub Action to setup [pontos](https://github.com/greenbone/pontos) for your
action or workflow.

```yml
name: Conventional Commits

on:
pull_request:

permissions:
pull-requests: write
contents: read

jobs:
conventional-commits:
name: Report Conventional Commits
runs-on: ubuntu-latest
steps:
- name: Report Conventional Commits
uses: greenbone/actions/conventional-commits@v2
with:
token: ${{ secrets.SOME_TOKEN }}
```
## Action Configuration
|Input Variable|Description| |
|--------------|-----------|-|
| token | GitHub token to create the pull request comments. | Optional (default is [`github.token`](https://docs.github.com/en/actions/learn-github-actions/contexts#github-context)) |
| python-version | Python version to use for running the action. | Optional (default is `3.10`) |
| poetry-version | Poetry version to use for running the action. | Optional (default is latest) |
| cache-poetry-installation | Cache poetry and its dependencies. | Optional (default is `true`) |
61 changes: 61 additions & 0 deletions setup-pontos/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: "Setup Pontos Action"
author: "Björn Ricks <bjoern.ricks@greenbone.net>"
description: "An action to setup python and pontos"
inputs:
cache-key:
description: "Key to use for the cache name."
default: "pontos-venv"
python-version:
description: "Python version that should be installed and used."
default: "3.10"
virtualenv-path:
description: "Path to the created virtual environment"
default: "${{ github.workspace }}/pontos-env"

outputs:
virtualenv-path:
description: "Path to the created virtual environment"
value: ${{ steps.virtualenv.outputs.path }}
activate:
description: "Path to the activate environment script to source"
value: ${{ steps.virtualenv.outputs.activate }}

branding:
icon: "package"
color: "green"

runs:
using: "composite"
steps:
- name: Virtual Environment
id: virtualenv
run: |
echo "path=${{ inputs.virtualenv-path }}" >> $GITHUB_OUTPUT
echo "activate=${{ inputs.virtualenv-path }}/bin/activate" >> $GITHUB_OUTPUT
shell: bash
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}
- name: Cache Virtual Environment
id: cache-virtualenv
uses: actions/cache@v3
with:
key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ inputs.cache-key }}
path: ${{ steps.virtualenv.outputs.path }}
- name: Create virtual environment
if: ${{ steps.cache-virtualenv.outputs.cache-hit != 'true' }}
run: |
python3 -m venv ${{ steps.virtualenv.outputs.path }}
shell: bash
- name: Install pontos
run: |
source ${{ steps.virtualenv.outputs.activate }}
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade pontos
shell: bash
- name: Print pontos version
run: |
source ${{ steps.virtualenv.outputs.activate }}
pontos --version
shell: bash
31 changes: 4 additions & 27 deletions sign-release-files/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,11 @@ runs:
echo "ARGS=${ARGS}" >> $GITHUB_ENV
shell: bash
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
id: python
with:
python-version: ${{ inputs.python-version }}
- name: Virtual Environment
- name: Set up Python and pontos
uses: greenbone/actions/setup-pontos@v2
id: virtualenv
run: |
echo "path=${{ github.action_path }}/${{ github.action }}-venv" >> $GITHUB_OUTPUT
echo "name=${{ github.action }}-venv" >> $GITHUB_OUTPUT
shell: bash
- name: Cache Virtual Environment
id: cache-virtualenv
uses: actions/cache@v3
with:
key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ steps.virtualenv.outputs.name }}
path: ${{ steps.virtualenv.outputs.path }}
- name: Create virtual environment
if: ${{ steps.cache-virtualenv.outputs.cache-hit != 'true' }}
run: |
python3 -m venv ${{ steps.virtualenv.outputs.path }}
shell: bash
- name: Install pontos
run: |
source ${{ steps.virtualenv.outputs.path }}/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade pontos
shell: bash
python-version: ${{ inputs.python-version }}
- name: Import gpg key from secrets
run: |
echo -e "${{ inputs.gpg-key }}" >> tmp.file
Expand All @@ -88,7 +65,7 @@ runs:
- name: Sign files for released version
run: |
echo "Signing release files"
source ${{ steps.virtualenv.outputs.path }}/bin/activate
source ${{ steps.virtualenv.outputs.activate }}
pontos-release sign ${{ env.ARGS }} --signing-key ${{ inputs.gpg-fingerprint }} --passphrase ${{ inputs.gpg-passphrase }} --versioning-scheme ${{ inputs.versioning-scheme }}
shell: bash
if: ${{ inputs.sign-release-files == 'true' }} && ${{ inputs.gpg-key }} && ${{ inputs.gpg-fingerprint }} && ${{ inputs.gpg-passphrase }}
Expand Down

0 comments on commit 9802104

Please sign in to comment.