Skip to content

Commit

Permalink
fix: pip cache key
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Jul 8, 2023
1 parent 96f2ed0 commit d2ae683
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 59 deletions.
23 changes: 18 additions & 5 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,31 @@ concurrency:

jobs:
run-this-action:
name: Run action (${{ matrix.runs-on }}, version ${{ matrix.version }})
runs-on: ${{ matrix.runs-on }}
name: Run action (${{ matrix.version }})
runs-on: [ubuntu-latest]
strategy:
fail-fast: false
matrix:
runs-on: [ubuntu-latest, macos-latest]
version: ["default", "0.6.11", "==0.6.11", "git+https://github.com/ApeWorX/ape.git@main"]
steps:
- uses: actions/checkout@v3

- name: Run this action
- name: Check version pin
id: check-version
run: |
if [[ ${{ matrix.version }} == "default" ]]; then
echo "ape-version=''" >> $GITHUB_OUTPUT
else
echo "ape-version=${{ matrix.version }}" >> $GITHUB_OUTPUT
fi
- name: Run ape action
id: ape-action
uses: ./
with:
version: ${{ matrix.version }}
ape-version-pin: ${{ steps.check-version.outputs.ape-version }}

- run: ape --help

- name: Print outputs
run: |
echo "Output: ${{ steps.ape-action.outputs.ape-version }}"
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"tabWidth": 2
}
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ Default is using Python `'3.8'`.
Default is to use the latest version of `eth-ape` (no pin).
Can also use a `git+` value to install a branch, commit, or tag.

Example values:

* `1.0.0`
* `==1.0.0`
* `>=1.0.0,<2.0`
* `git+https://github.com/your-github/ape.git@your-branch`

### `ape-plugins-list`

**Optional** Space-separated list of plugins to install.
Expand All @@ -24,7 +31,10 @@ Note: When requesting a pin, put it all together like `'plugin-a plugin-b==1.2.3

## Outputs

No outputs.
### `ape-version`

The version of Ape installed.
This will either be the same as the `ape-version-pin` input if you provided that, else it will be the latest version found from `pypi`.

## Example usage

Expand All @@ -33,9 +43,9 @@ steps:
- uses: actions/checkout@v3
- uses: ApeWorX/github-action@v2
with:
python-version: "3.10" # (optional)
ape-version-pin: ">=0.6.0" # (optional)
ape-plugins-list: "solidity vyper==0.6.2" # (optional)
python-version: '3.10' # (optional)
ape-version-pin: '>=0.6.0' # (optional)
ape-plugins-list: 'solidity vyper==0.6.2' # (optional)
- run: ape test -s
```
Expand Down
122 changes: 72 additions & 50 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ branding:
color: 'green'

inputs:
python-version:
python-version:
description: 'Override version of python used to run ape- default 3.8'
required: False
default: '3.8'
Expand All @@ -18,64 +18,86 @@ inputs:
required: False
default: '-U .'

outputs:
ape-version:
description: 'The version of Ape installed'

runs:
using: 'composite'

steps:

- uses: actions/cache@v3
with:
path: |
/home/runner/.solcx
/home/runner/.vvm/vyper-*
key: ${{ runner.os }}-compiler-cache
- uses: actions/cache@v3
with:
path: |
/home/runner/.solcx
/home/runner/.vvm/vyper-*
key: ${{ runner.os }}-compiler-cache

- uses: actions/cache@v3
with:
path: |
${{ github.workspace }}/.build
key: ${{ runner.os }}-build-cache
- uses: actions/cache@v3
with:
path: |
${{ github.workspace }}/.build
key: ${{ runner.os }}-build-cache

- uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}

- name: Set pip cache directory path
id: pip-cache-dir-path
run: |
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}

- name: Restore pip cache
uses: actions/cache@v3
id: pip-cache
with:
path: |
${{ steps.pip-cache-dir-path.outputs.dir }}
key: ${{ inputs.python-version }}-pip-${{ inputs.ape-version-pin }}
- name: Set pip cache directory path
id: pip-cache-dir-path
run: |
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
shell: bash

- run: |
pip install --upgrade pip
if [[ "${{ inputs.ape-version-pin }}" == git+* ]]
then
echo "INFO: Installing from a remote git version."
pip install ${{ inputs.ape-version-pin }}
else
pip install eth-ape${{ inputs.ape-version-pin }}
fi
shell: bash
- name: Determine ape version to use
id: determine-version
run: |
if [[ "${{ inputs.ape-version-pin }}" != "" && "${{ inputs.ape-version-pin }}" != "''" ]]; then
echo "ape-version=${{ inputs.ape-version-pin }}" >> $GITHUB_OUTPUT
else
latest_version=$(curl -s https://pypi.org/pypi/eth-ape/json | jq -r '.info.version')
echo "ape-version=${latest_version}" >> $GITHUB_OUTPUT
fi
shell: bash

- run: ape plugins install ${{ inputs.ape-plugins-list }}
shell: bash
- name: Restore pip cache
uses: actions/cache@v3
id: pip-cache
with:
path: |
${{ steps.pip-cache-dir-path.outputs.dir }}
key: ${{ inputs.python-version }}-pip-${{ steps.determine-version.outputs.ape-version }}

- name: Find if requirements.txt if exists
id: find-requirements-txt
run: |
echo "file=$(ls requirements.txt)" >> $GITHUB_OUTPUT
shell: bash
- name: Install Ape
run: |
pip install --upgrade pip
if [[ "${{ steps.determine-version.outputs.ape-version }}" == git+* ]]
then
echo "INFO: Installing from a remote git version."
pip install ${{ steps.determine-version.outputs.ape-version }}
else
version_regex='^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$'
if [[ ${{ steps.determine-version.outputs.ape-version }} =~ $version_regex ]]; then
# Allows for excluding `==` to `ape-version-pin`
echo "Installing with == prefix"
pip install eth-ape==${{ steps.determine-version.outputs.ape-version }}
else
echo "Installing using given constraints"
pip install eth-ape${{ steps.determine-version.outputs.ape-version }}
fi
fi
shell: bash

- name: Install requirements.txt
run: pip install -r requirements.txt
shell: bash
if: steps.find-requirements-txt.outputs.file == 'requirements.txt'
- run: ape plugins install ${{ inputs.ape-plugins-list }}
shell: bash

- name: Find if requirements.txt if exists
id: find-requirements-txt
run: |
echo "file=$(ls requirements.txt)" >> $GITHUB_OUTPUT
shell: bash

- name: Install requirements.txt
run: pip install -r requirements.txt
shell: bash
if: steps.find-requirements-txt.outputs.file == 'requirements.txt'

0 comments on commit d2ae683

Please sign in to comment.