Skip to content

Commit

Permalink
feat(GHA): create composite action for setup
Browse files Browse the repository at this point in the history
  • Loading branch information
vringar committed Aug 6, 2024
1 parent f2b9640 commit a03fc7c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 98 deletions.
40 changes: 40 additions & 0 deletions .github/actions/setup/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: 'Setup OpenWPM env'
description: 'Sets up conda and installs dependencies'
runs:
using: "composite"
steps:
# All of these steps are just setup
- name: Setting MAMBA_PATH
shell: bash
run: echo "MAMBA_PATH=$HOME/mamba" >> $GITHUB_ENV
- name: Setting OPENWPM_MAMBA_PATH
shell: bash
run: echo "OPENWPM_MAMBA_PATH=$MAMBA_PATH/envs/openwpm" >> $GITHUB_ENV
# If the environment.yaml hasn't changed we just reuse the entire conda install
- id: cache
uses: actions/cache@v4
env:
cache-name: conda-cache
with:
path: ${{ env.MAMBA_PATH }}
key: ${{ env.cache-name }}-${{ hashFiles('environment.yaml') }}

- name: Install conda
shell: bash
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
run: $GITHUB_WORKSPACE/scripts/install-mamba.sh

- shell: bash
run: echo "$MAMBA_PATH/bin" >> $GITHUB_PATH

- name: Install.sh (cache miss)
shell: bash
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
run: $GITHUB_WORKSPACE/install.sh
- name: Install.sh (cache hit)
shell: bash
if: ${{ steps.cache.outputs.cache-hit == 'true' }}
run: $GITHUB_WORKSPACE/install.sh --skip-create
- shell: bash
run: echo "$OPENWPM_MAMBA_PATH/bin" >> $GITHUB_PATH
# Now we have a working OpenWPM environment
101 changes: 3 additions & 98 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,71 +13,15 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
# All of these steps are just setup
- uses: actions/checkout@v4
- name: Setting MAMBA_PATH
run: echo "MAMBA_PATH=$HOME/mamba" >> $GITHUB_ENV
- name: Setting OPENWPM_MAMBA_PATH
run: echo "OPENWPM_MAMBA_PATH=$MAMBA_PATH/envs/openwpm" >> $GITHUB_ENV
# If the environment.yaml hasn't changed we just reuse the entire conda install
- id: cache
uses: actions/cache@v4
env:
cache-name: conda-cache
with:
path: ${{ env.MAMBA_PATH }}
key: ${{ env.cache-name }}-${{ hashFiles('environment.yaml') }}

- name: Install conda
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
run: $GITHUB_WORKSPACE/scripts/install-mamba.sh

- run: echo "$MAMBA_PATH/bin" >> $GITHUB_PATH

- name: Install.sh (cache miss)
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
run: $GITHUB_WORKSPACE/install.sh
- name: Install.sh (cache hit)
if: ${{ steps.cache.outputs.cache-hit == 'true' }}
run: $GITHUB_WORKSPACE/install.sh --skip-create
- run: echo "$OPENWPM_MAMBA_PATH/bin" >> $GITHUB_PATH
# Now we have a working OpenWPM environment

- uses: ./.github/actions/setup
- run: pre-commit run --all

demo:
runs-on: ubuntu-latest
steps:
# All of these steps are just setup
- uses: actions/checkout@v4
- name: Setting MAMBA_PATH
run: echo "MAMBA_PATH=$HOME/mamba" >> $GITHUB_ENV
- name: Setting OPENWPM_MAMBA_PATH
run: echo "OPENWPM_MAMBA_PATH=$MAMBA_PATH/envs/openwpm" >> $GITHUB_ENV
# If the environment.yaml hasn't changed we just reuse the entire conda install
- id: cache
uses: actions/cache@v4
env:
cache-name: conda-cache
with:
path: ${{ env.MAMBA_PATH }}
key: ${{ env.cache-name }}-${{ hashFiles('environment.yaml') }}

- name: Install conda
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
run: $GITHUB_WORKSPACE/scripts/install-mamba.sh

- run: echo "$MAMBA_PATH/bin" >> $GITHUB_PATH

- name: Install.sh (cache miss)
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
run: $GITHUB_WORKSPACE/install.sh
- name: Install.sh (cache hit)
if: ${{ steps.cache.outputs.cache-hit == 'true' }}
run: $GITHUB_WORKSPACE/install.sh --skip-create
- run: echo "$OPENWPM_MAMBA_PATH/bin" >> $GITHUB_PATH
# Now we have a working OpenWPM environment

- uses: ./.github/actions/setup
- run: python demo.py --headless
tests:
runs-on: ubuntu-latest
Expand All @@ -95,47 +39,8 @@ jobs:
]
fail-fast: false
steps:
# All of these steps are just setup, maybe we should wrap them in an action
- uses: actions/checkout@v4
- name: Cache node modules
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
# Setting env variables that depend on $HOME
- name: Setting MAMBA_PATH
run: echo "MAMBA_PATH=$HOME/mamba" >> $GITHUB_ENV
- name: Setting OPENWPM_MAMBA_PATH
run: echo "OPENWPM_MAMBA_PATH=$MAMBA_PATH/envs/openwpm" >> $GITHUB_ENV

# If the environment.yaml hasn't changed we just reuse the entire conda install
- id: conda-cache
uses: actions/cache@v4
env:
cache-name: conda-cache
with:
path: ${{ env.MAMBA_PATH }}
key: ${{ env.cache-name }}-${{ hashFiles('environment.yaml') }}

- name: Install conda
if: ${{ steps.conda-cache.outputs.cache-hit != 'true' }}
run: $GITHUB_WORKSPACE/scripts/install-mamba.sh

- run: echo "$MAMBA_PATH/bin" >> $GITHUB_PATH

- name: Install.sh (cache miss)
if: ${{ steps.conda-cache.outputs.cache-hit != 'true' }}
run: $GITHUB_WORKSPACE/install.sh
- name: Install.sh (cache hit)
if: ${{ steps.conda-cache.outputs.cache-hit == 'true' }}
run: $GITHUB_WORKSPACE/install.sh --skip-create

- run: echo "$OPENWPM_MAMBA_PATH/bin" >> $GITHUB_PATH
# Now we have a working OpenWPM environment

- uses: ./.github/actions/setup
- run: ./scripts/ci.sh
env:
DISPLAY: ":99.0"
Expand Down

0 comments on commit a03fc7c

Please sign in to comment.