Skip to content

Commit

Permalink
tests: added feature tagging on master pushes of only changed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maykathm committed Feb 28, 2025
1 parent feef96e commit 44ba42a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 13 deletions.
46 changes: 33 additions & 13 deletions .github/workflows/feature-tagging.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Feature Tagging

on:
push:
branches: ["master"]

workflow_dispatch:
inputs:
features:
Expand All @@ -11,8 +14,25 @@ on:
type: number
description: 'Maximum number of times to rerun failed spread tasks upon failure'
default: 3
run-all:
type: boolean
description: 'If true, will run all spread tests. If false, will only run tagging on changed spread tests in the last commit'
default: false

jobs:
set-inputs:
runs-on: ubuntu-latest
outputs:
features: ${{ steps.step1.outputs.features }}
maximum-reruns: ${{ steps.step1.outputs.maximum-reruns }}
run-all: ${{ steps.step1.outputs.run-all }}
steps:
- name: Set inputs
run: |
echo "features=${{ inputs.features || 'all' }}" >> $GITHUB_OUTPUT
echo "maximum-reruns=${{ inputs.maximum-reruns || 3 }}" >> $GITHUB_OUTPUT
echo "run-all=${{ inputs.run-all || false }}" >> $GITHUB_OUTPUT
read-systems:
runs-on: ubuntu-latest
outputs:
Expand All @@ -33,62 +53,62 @@ jobs:
tag-features-fundamental:
uses: ./.github/workflows/spread-tests.yaml
needs: [read-systems]
needs: [set-inputs, read-systems]
name: "spread ${{ matrix.group }}"
with:
runs-on: '["self-hosted", "spread-enabled"]'
group: ${{ matrix.group }}
backend: ${{ matrix.backend }}
systems: ${{ matrix.systems }}
tasks: ${{ matrix.tasks }}
rules: ${{ matrix.rules }}
rules: ${{ needs.set-inputs.outputs.run-all && matrix.rules || feature-tagging.yaml }}
is-fundamental: true
use-snapd-snap-from-master: true
spread-tag-features: ${{ inputs.features }}
spread-tag-features: ${{ needs.set-inputs.outputs.features }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.read-systems.outputs.fundamental-systems) }}

tag-features-non-fundamental:
uses: ./.github/workflows/spread-tests.yaml
needs: [read-systems]
needs: [set-inputs, read-systems]
name: "spread ${{ matrix.group }}"
with:
runs-on: '["self-hosted", "spread-enabled"]'
group: ${{ matrix.group }}
backend: ${{ matrix.backend }}
systems: ${{ matrix.systems }}
tasks: ${{ matrix.tasks }}
rules: ${{ matrix.rules }}
rules: ${{ needs.set-inputs.outputs.run-all && matrix.rules || feature-tagging.yaml }}
use-snapd-snap-from-master: true
spread-tag-features: ${{ inputs.features }}
spread-tag-features: ${{ needs.set-inputs.outputs.features }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.read-systems.outputs.non-fundamental-systems) }}

tag-features-nested:
uses: ./.github/workflows/spread-tests.yaml
needs: [read-systems]
needs: [set-inputs, read-systems]
name: "spread ${{ matrix.group }}"
with:
runs-on: '["self-hosted", "spread-enabled"]'
group: ${{ matrix.group }}
backend: ${{ matrix.backend }}
systems: ${{ matrix.systems }}
tasks: ${{ matrix.tasks }}
rules: ${{ matrix.rules }}
rules: ${{ needs.set-inputs.outputs.run-all && matrix.rules || feature-tagging.yaml }}
use-snapd-snap-from-master: true
spread-tag-features: ${{ inputs.features }}
spread-tag-features: ${{ needs.set-inputs.outputs.features }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.read-systems.outputs.nested-systems) }}

re-run:
permissions:
actions: write
needs: [tag-features-fundamental, tag-features-non-fundamental, tag-features-nested]
needs: [set-inputs, tag-features-fundamental, tag-features-non-fundamental, tag-features-nested]
# If the spread tests ended in failure, rerun the workflow up to maximum-reruns-1 times
if: failure() && fromJSON(github.run_attempt) < fromJSON(inputs.maximum-reruns)
if: failure() && fromJSON(github.run_attempt) < fromJSON(needs.set-inputs.outputs.maximum-reruns)
runs-on: ubuntu-latest
steps:
- env:
Expand All @@ -97,9 +117,9 @@ jobs:
run: gh workflow run rerun.yaml -F run_id=${{ github.run_id }}

create-reports:
needs: [tag-features-fundamental, tag-features-non-fundamental, tag-features-nested]
needs: [set-inputs, tag-features-fundamental, tag-features-non-fundamental, tag-features-nested]
runs-on: ubuntu-latest
if: success() || fromJSON(github.run_attempt) >= fromJSON(inputs.maximum-reruns)
if: success() || fromJSON(github.run_attempt) >= fromJSON(needs.set-inputs.outputs.maximum-reruns)
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
18 changes: 18 additions & 0 deletions tests/lib/spread/rules/feature-tagging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
rules:
tests:
from:
- tests/main/.*/task.yaml
- tests/core/.*/task.yaml
- tests/completion/.*/task.yaml
- tests/cross/.*/task.yaml
- tests/regression/.*/task.yaml
- tests/smoke/.*/task.yaml
- tests/unit/.*/task.yaml
- tests/upgrade/.*/task.yaml
- tests/fips/.*/task.yaml
- tests/nested/.*/task.yaml
to: [$SELF]

rest:
from: [.*]
to: [$NONE]

0 comments on commit 44ba42a

Please sign in to comment.