Skip to content

Commit

Permalink
Port update reference data pipeline to GitHub Actions (#2249)
Browse files Browse the repository at this point in the history
* Create new workflow

* Patch for arepo tests

* Restore deleted parameter

* Black format; Add missing skip reason

* Fix typo in comment

* Add more comments

* Create slash command dispatcher

* Changes to dispatcher

* Black format

* Adapt workflow to run on workflow dispatch; create pull request step

* Black format

* Minor fixes

* Add bot comments after result

* Remove Azure Pipelines YAML file

* Do not push .lfs-assets-id on pull request
  • Loading branch information
epassaro authored Apr 4, 2023
1 parent 21e86c4 commit 6cf502f
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 69 deletions.
69 changes: 0 additions & 69 deletions .azure-pipelines/update-refdata.yml

This file was deleted.

21 changes: 21 additions & 0 deletions .github/workflows/dispatcher.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: slash-command
on:
issue_comment:
types: [created]

jobs:
dispatch:
runs-on: ubuntu-latest
steps:
- name: Slash Command Dispatcher
uses: peter-evans/slash-command-dispatch@v3
with:
token: ${{ secrets.BOT_TOKEN }}
commands: |
compare-refdata
update-refdata
repository: tardis-sn/tardis
issue-type: pull-request
permission: triage
reaction-token: ${{ secrets.BOT_TOKEN }}
allow-edits: true
150 changes: 150 additions & 0 deletions .github/workflows/update-refdata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# For more information about TARDIS pipelines, please refer to:
#
# https://tardis-sn.github.io/tardis/development/continuous_integration.html

name: update-refdata

on:
repository_dispatch:
types: [update-refdata-command]

env:
PYTEST_FLAGS: --tardis-refdata=${{ github.workspace }}/tardis-refdata --generate-reference
CACHE_NUMBER: 1 # increase to reset cache manually

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

defaults:
run:
shell: bash -l {0}

jobs:
pr-open:
runs-on: ubuntu-latest
steps:
- name: Checkout pull/${{ github.event.client_payload.pull_request.number }}
uses: actions/checkout@v3
with:
ref: ${{ github.event.client_payload.pull_request.head.sha }}

- uses: actions/checkout@v3
with:
repository: tardis-sn/tardis-refdata
path: tardis-refdata
lfs: false

- name: Create LFS file list
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id
working-directory: tardis-refdata

- name: Restore LFS cache
uses: actions/cache@v3
id: lfs-cache
with:
path: tardis-refdata/.git/lfs
key: ${{ runner.os }}-lfs-${{ hashFiles('tardis-refdata/.lfs-assets-id') }}-v${{ env.CACHE_NUMBER }}

- name: Pull LFS objects
run: git lfs pull
working-directory: tardis-refdata
if: steps.lfs-cache.outputs.cache-hit != 'true'

- name: Checkout LFS repository
run: git lfs checkout
working-directory: tardis-refdata
if: steps.lfs-cache.outputs.cache-hit == 'true'

- name: Setup environment
uses: conda-incubator/setup-miniconda@v2
with:
miniforge-variant: Mambaforge
miniforge-version: latest
activate-environment: tardis
use-mamba: true

- uses: actions/cache@v3
with:
path: /usr/share/miniconda3/envs/tardis
key: conda-linux-64-${{ hashFiles('conda-linux-64.lock') }}-v${{ env.CACHE_NUMBER }}
id: cache-conda

- name: Update environment
run: mamba update -n tardis --file conda-linux-64.lock
if: steps.cache-conda.outputs.cache-hit != 'true'

- name: Install package
run: pip install -e .

- name: Generate new reference data
run: pytest tardis ${{ env.PYTEST_FLAGS }}

- name: Remove unwanted files
run: rm .lfs-assets-id

- name: Create pull request
uses: peter-evans/create-pull-request@v4
with:
path: tardis-refdata
token: ${{ secrets.BOT_TOKEN }}
committer: TARDIS Bot <[email protected]>
author: TARDIS Bot <[email protected]>
branch: pr-${{ github.event.client_payload.pull_request.number }}
base: master
push-to-fork: tardis-bot/tardis-refdata
commit-message: Automated update (tardis pr-${{ github.event.client_payload.pull_request.number }})
title: Automated update (tardis pr-${{ github.event.client_payload.pull_request.number }})
body: |
*\*beep\* \*bop\**
Hi, human.
These are the changes made by https://github.com/tardis-sn/tardis/pull/${{ github.event.client_payload.pull_request.number }}, please be careful before merging this pull request.
id: create-pr

- name: Find comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ github.event.client_payload.pull_request.number }}
body-includes: Hi, human.
if: always()

- name: Post comment (success)
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ secrets.BOT_TOKEN }}
issue-number: ${{ github.event.client_payload.pull_request.number }}
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
body: |
*\*beep\* \*bop\**
Hi, human.
The **`${{ github.workflow }}`** workflow has **succeeded** :heavy_check_mark:
[**Click here**](${{ env.URL }}) to see your results.
env:
URL: https://github.com/tardis-sn/tardis-refdata/pull/${{ github.event.client_payload.pull_request.number }}
if: success()

- name: Post comment (failure)
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ secrets.BOT_TOKEN }}
issue-number: ${{ github.event.number }}
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
body: |
*\*beep\* \*bop\**
Hi, human.
The **`${{ github.workflow }}`** workflow has **failed** :x:
[**Click here**](${{ env.URL }}) to see the build log.
env:
URL: https://github.com/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/runs/${{ github.run_id }}?check_suite_focus=true
if: failure()
17 changes: 17 additions & 0 deletions tardis/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ def pytest_configure(config):
packagename = os.path.basename(os.path.dirname(__file__))
TESTED_VERSIONS[packagename] = __version__

# Create a marker to ignore the `--generate-reference` flag. A use case for this
# marker is when there is data in the reference data repository that can't be
# generated by TARDIS, like the Arepo snapshots.
config.addinivalue_line(
"markers",
"ignore_generate: mark test to not generate new reference data",
)


# Uncomment the last two lines in this block to treat all DeprecationWarnings as
# exceptions. For Astropy v2.0 or later, there are 2 additional keywords,
Expand Down Expand Up @@ -100,6 +108,15 @@ def pytest_addoption(parser):
)


# Required by the `ignore_generate` marker
def pytest_collection_modifyitems(config, items):
if config.getoption("--generate-reference"):
skip_generate = pytest.mark.skip(reason="Skip generate reference data")
for item in items:
if "ignore_generate" in item.keywords:
item.add_marker(skip_generate)


# -------------------------------------------------------------------------
# project specific fixtures
# -------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions tardis/io/tests/test_arepo_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ def get_full_reference_data():
return data


@pytest.mark.ignore_generate
def test_cone_profile(get_cone_csvy_model, get_cone_reference_data):
assert get_cone_csvy_model == get_cone_reference_data


@pytest.mark.ignore_generate
def test_full_profile(get_full_csvy_model, get_full_reference_data):
assert get_full_csvy_model == get_full_reference_data

0 comments on commit 6cf502f

Please sign in to comment.