Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement update test data #22

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions .github/workflows/tools_update_test_data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
on: [push, pull_request]

name: 'Test action for tools with update test data'

env:
GALAXY_FORK: galaxyproject
GALAXY_BRANCH: master
MAX_CHUNKS: 4

jobs:
setup-pr-tools:
name: Setup as in PR for tools
runs-on: ubuntu-latest
outputs:
galaxy-head-sha: ${{ steps.get-galaxy-sha.outputs.galaxy-head-sha }}
repository-list: ${{ steps.discover.outputs.repository-list }}
tool-list: ${{ steps.discover.outputs.tool-list }}
chunk-count: ${{ steps.discover.outputs.chunk-count }}
chunk-list: ${{ steps.discover.outputs.chunk-list }}
strategy:
matrix:
python-version: [3.7]
steps:
- name: Print github context properties
run: |
echo 'event: ${{ github.event_name }}'
echo 'sha: ${{ github.sha }}'
echo 'ref: ${{ github.ref }}'
echo 'head_ref: ${{ github.head_ref }}'
echo 'base_ref: ${{ github.base_ref }}'
echo 'event.before: ${{ github.event.before }}'
echo 'event.after: ${{ github.event.after }}'
- name: Determine latest commit in the Galaxy repo
id: get-galaxy-sha
run: echo "::set-output name=galaxy-head-sha::$(git ls-remote https://github.com/${{ env.GALAXY_FORK }}/galaxy refs/heads/${{ env.GALAXY_BRANCH }} | cut -f1)"
- uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Cache .cache/pip and .planemo
uses: actions/cache@v2
id: cache-pip-planemo
with:
path: |
~/.cache/pip
~/.planemo
key: cache_py_${{ matrix.python-version }}_gxy_${{ steps.get-galaxy-sha.outputs.galaxy-head-sha }}
# Install the `wheel` package so that when installing other packages which
# are not available as wheels, pip will build a wheel for them, which can be cached.
- name: Install wheel
run: pip install wheel
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Introduce a change on test tool1 and 2
run: |
git config --global user.name "Arthur Dent"
git config --global user.email "[email protected]"
sed -i -e 's/echo test/echo updated/' test/tools/tool1/tool1.xml
sed -i -e 's/echo test/echo updated/' test/tools/tool2/tool2.xml
git commit -m bump test/tools/
- name: Fake a Planemo run to update cache and determine commit range, repositories, and chunks
uses: ./
id: discover
with:
create-cache: ${{ steps.cache-pip.outputs.cache-hit != 'true' || steps.cache-planemo.outputs.cache-hit != 'true' }}
galaxy-fork: ${{ env.GALAXY_FORK }}
galaxy-branch: ${{ env.GALAXY_BRANCH }}
max-chunks: ${{ env.MAX_CHUNKS }}
python-version: ${{ matrix.python-version }}
update-test-data: true
- name: Check commit range
run: if ! grep "\.\." <<<$(echo ${{ steps.discover.outputs.commit-range }}); then echo "wrong commit range"; exit 1; fi
- name: Check content of repository list
run: |
if ! grep -q "tool1" <<<$(echo "${{ steps.discover.outputs.repository-list }}"); then echo "tool1 must be in repo list"; exit 1; fi
if ! grep -q "tool2" <<<$(echo "${{ steps.discover.outputs.repository-list }}"); then echo "tool2 must be in repo list"; exit 1; fi
- name: Check content of tool list
run: |
if ! grep -q "tool1.xml" <<<$(echo "${{ steps.discover.outputs.tool-list }}"); then echo "tool1.xml must be in tool list"; exit 1; fi
if ! grep -q "tool2.xml" <<<$(echo "${{ steps.discover.outputs.tool-list }}"); then echo "tool2.xml must be in tool list"; exit 1; fi
- name: Check number of chunks
run: if [ "${{ steps.discover.outputs.chunk-count }}" != "1" ]; then echo "wrong chunk-count"; exit 1; fi


test-tools:
name: Test testing of tools
needs: [setup-pr-tools]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
chunk: ${{ fromJson(needs.setup-pr-tools.outputs.chunk-list) }}
python-version: [3.7]
services:
postgres:
image: postgres:11
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
steps:
# checkout the repository
# and use it as the current working directory
- uses: actions/checkout@v2
with:
fetch-depth: 1
- uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Cache .cache/pip and .planemo
uses: actions/cache@v2
id: cache-pip-planemo
with:
path: |
~/.cache/pip
~/.planemo
key: cache_py_${{ matrix.python-version }}_gxy_${{ needs.setup-pr-tools.outputs.galaxy-head-sha }}
- name: Introduce a change on test tool1 and 2
run: |
sed -i -e 's/echo test/echo updated/' test/tools/tool1/tool1.xml
sed -i -e 's/echo test/echo updated/' test/tools/tool2/tool2.xml
- name: Planemo test tools
uses: ./
id: test-tools
with:
mode: test
repository-list: ${{ needs.setup-pr-tools.outputs.repository-list }}
galaxy-fork: ${{ env.GALAXY_FORK }}
galaxy-branch: ${{ env.GALAXY_BRANCH }}
chunk: ${{ matrix.chunk }}
chunk-count: ${{ needs.setup-pr-tools.outputs.chunk-count }}
update-test-data: true
- name: Check if test updated the test data
run: |
if ! grep -q "updated" test/tools/tool1/test-data/test.txt; then echo "test data for tool1 has not been updated"; exit 1; fi
- uses: actions/upload-artifact@v2
with:
name: 'Tool test output ${{ matrix.chunk }}'
path: upload
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Optional inputs:
- `galaxy-source` (default `galaxyproject`)
- `max-chunks` (default `20`)
- `python-version` (default `"3.7"`)
- `update-test-data` Boolean that sets the number of chunks to one. See documentation in test mode.

Outputs:

Expand Down Expand Up @@ -107,6 +108,7 @@ Optional inputs:
- `galaxy-branch`
- `galaxy-source`
- `python-version`
- `update-test-data` Boolean that triggers the update of test data for failed tests. If you intend to commit the changes during IUC style CI the also set this in setup mode (which will set the number of chunks to 1).

Output:

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ inputs:
workflow-namespace:
description: 'Github namespace under which to create workfow repositories'
default: 'iwc-workflows'
update-test-data:
description: 'Flag to trigger update of test data for test mode'
default: false
github-token:
description: '(Secret!) Github PAT token. Needed for creating workflow repositories with workflow-upload'
default: ''
Expand Down Expand Up @@ -126,6 +129,7 @@ runs:
WORKFLOW_NAMESPACE: ${{ inputs.workflow-namespace }}
GITHUB_TOKEN: ${{ inputs.github-token }}
WORKFLOWS: ${{ inputs.workflows }}
UPDATE_TEST_DATA: ${{ inputs.update-test-data }}
GITHUB_EVENT_NAME_OVERRIDE: ${{ inputs.github-event-name-override }}
GITHUB_REF_OVERRIDE: ${{ inputs.github-ref-override }}

Expand Down
19 changes: 13 additions & 6 deletions planemo_ci_actions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if [ "$REPOSITORIES" == "" ] && [ "$MODE" == "setup" ]; then
fi
;;
esac
elif [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
elif [ "$GITHUB_EVENT_NAME" = "pull_request" ] || [ "$GITHUB_EVENT_NAME" = "repository_dispatch" ]; then
COMMIT_RANGE="HEAD~.."
fi
echo "$COMMIT_RANGE" > commit_range.txt
Expand Down Expand Up @@ -85,11 +85,15 @@ if [ "$REPOSITORIES" == "" ] && [ "$MODE" == "setup" ]; then
ln -s repository_list.txt count_list.txt
fi

CHUNK_COUNT=$(wc -l < count_list.txt)
if [ "$CHUNK_COUNT" -gt "$MAX_CHUNKS" ]; then
CHUNK_COUNT=$MAX_CHUNKS
elif [ "$CHUNK_COUNT" -eq 0 ]; then
if [ "$UPDATE_TEST_DATA" == "true" ]; then
CHUNK_COUNT=1
else
CHUNK_COUNT=$(wc -l < count_list.txt)
if [ "$CHUNK_COUNT" -gt "$MAX_CHUNKS" ]; then
CHUNK_COUNT=$MAX_CHUNKS
elif [ "$CHUNK_COUNT" -eq 0 ]; then
CHUNK_COUNT=1
fi
fi
echo $CHUNK_COUNT > chunk_count.txt
else
Expand Down Expand Up @@ -158,7 +162,10 @@ if [ "$MODE" == "test" ]; then
fi
if [ "$WORKFLOWS" == "true" ]; then
PLANEMO_OPTIONS+=("${PLANEMO_WORKFLOW_OPTIONS[@]}")
fi
fi
if [ "$UPDATE_TEST_DATA" == "true" ]; then
PLANEMO_OPTIONS+=("--update_test_data")
fi
json=$(mktemp -u -p json_output --suff .json)
PIP_QUIET=1 planemo test "${PLANEMO_OPTIONS[@]}" "${PLANEMO_TEST_OPTIONS[@]}" --test_output_json "$json" "${TOOL_GROUP[@]}" || true
docker system prune --all --force --volumes || true
Expand Down
1 change: 1 addition & 0 deletions test/tools/tool1/test-data/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
6 changes: 1 addition & 5 deletions test/tools/tool1/tool1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
<tests>
<test>
<param name="bool" value="true"/>
<output name="out">
<assert_contents>
<has_text text="test"/>
</assert_contents>
</output>
<output name="out" value="test.txt"/>
</test>
</tests>
<help><![CDATA[
Expand Down
1 change: 1 addition & 0 deletions test/tools/tool2/test-data/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
6 changes: 1 addition & 5 deletions test/tools/tool2/tool2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
<tests>
<test>
<param name="bool" value="true"/>
<output name="out">
<assert_contents>
<has_text text="test"/>
</assert_contents>
</output>
<output name="out" value="test.txt"/>
</test>
</tests>
<help><![CDATA[
Expand Down