♻️ Add dynamic matrix generation for changed files in test job #31
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test and Release | |
permissions: | |
id-token: "write" | |
contents: "write" | |
packages: "write" | |
pull-requests: "read" | |
on: | |
push: | |
branches: | |
- '**' | |
tags: | |
- '*' | |
jobs: | |
changed: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- run: sudo apt-get update && sudo apt-get install -y jq | |
- name: Get changed file names | |
id: set-matrix | |
run: | | |
changed_files_tags=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | sed -n '/^tasks\/.*\.wdl$/s|^tasks/||; s|\.wdl$||p') | |
echo "::set-output name=matrix::$(echo $changed_files_tags | jq -R 'split(" ") | map({tag: .})')" | |
shell: bash -eo pipefail {0} | |
test: | |
runs-on: ubuntu-latest | |
needs: changed | |
strategy: | |
fail-fast: false | |
matrix: ${{fromJson(needs.changed.outputs.matrix)}} | |
services: | |
docker: | |
image: docker:19.03.12 | |
options: --privileged | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.9' | |
cache: 'pip' # caching pip dependencies | |
- name: Install Python dependencies | |
run: pip install -r tests/requirements.txt | |
- name: Run test ${{ matrix.tag }} | |
run: pytest --tag ${{ matrix.tag }} tests/tasks | |
release: | |
needs: [test] | |
if: startsWith(github.ref, 'refs/tags/') | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Create tar.gz of directories | |
run: | | |
# Change to the parent directory | |
cd .. | |
# Extract the tag name from GITHUB_REF (assuming it's a tag push) | |
TAG_NAME=$(echo $GITHUB_REF | sed 's#refs/tags/##') | |
# Create a file with the tag name | |
echo "Version: $TAG_NAME" > wdl-hub/version.txt | |
# Find .wdl files and include the version file in the tar.gz archive | |
find wdl-hub -type f -name "*.wdl" -print > filelist.txt | |
echo wdl-hub/version.txt >> filelist.txt | |
tar -czvf release.tar.gz --files-from=filelist.txt | |
# Change back to the original directory | |
cd - | |
- name: Create a Release | |
uses: "marvinpinto/action-automatic-releases@latest" | |
with: | |
repo_token: "${{ secrets.GITHUB_TOKEN }}" | |
prerelease: false | |
files: | | |
../release.tar.gz |