fix(workflow-dispatcher): Group push jobs into single job #5
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
on: | ||
workflow_call: | ||
inputs: | ||
skip: | ||
required: false | ||
type: string | ||
default: '' | ||
main_branches: | ||
required: false | ||
type: string | ||
default: 'main,master' | ||
event_name: | ||
required: true | ||
type: string | ||
run_id: | ||
required: true | ||
type: string | ||
rcmdcheck_args: | ||
required: false | ||
type: string | ||
default: 'c("--no-manual", "--as-cran", "--no-tests")' | ||
schemas: | ||
required: false | ||
type: string | ||
backend_exclude: | ||
required: false | ||
type: string | ||
jobs: | ||
# To give granular control of when workflows should execute, we determine which "categories" of files has changed | ||
trigger: | ||
name: ⚙️ Determine downstream workflow triggers | ||
runs-on: ubuntu-latest | ||
outputs: | ||
R_files_changed: ${{ steps.changed-files-yaml.outputs.R_any_changed }} | ||
test_files_changed: ${{ steps.changed-files-yaml.outputs.test_any_changed }} | ||
man_files_changed: ${{ steps.changed-files-yaml.outputs.man_any_changed }} | ||
vignette_files_changed: ${{ steps.changed-files-yaml.outputs.vignette_any_changed }} | ||
readme_files_changed: ${{ steps.changed-files-yaml.outputs.readme_any_changed }} | ||
description_changed: ${{ steps.changed-files-yaml.outputs.description_any_changed }} | ||
main_branch_affected: ${{ steps.main_branch_affected.outputs.main_branch_affected }} | ||
branch_name: ${{ steps.branch_name.outputs.branch_name }} | ||
cache_version: ${{ steps.cache_version.outputs.cache_version }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Detect changes to R/, tests/, man/, vignettes/, README.Rmd and DESCRIPTION | ||
id: changed-files-yaml | ||
uses: tj-actions/changed-files@v41 | ||
with: | ||
files_yaml: | | ||
R: | ||
- R/** | ||
test: | ||
- tests/** | ||
man: | ||
- man/** | ||
vignette: | ||
- vignettes/** | ||
readme: | ||
- README.md | ||
- README.Rmd | ||
- .github/templates/README_template.Rmd | ||
description: | ||
- DESCRIPTION | ||
- name: Determine branch name | ||
id: branch_name | ||
shell: bash | ||
run: | | ||
echo "branch_name=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT | ||
- name: Determine main branch involvement | ||
id: main_branch_affected | ||
shell: bash | ||
run: | | ||
if [ "${{ inputs.event_name }}" == "pull_request" ] && [[ "${{ inputs.main_branches }}" == *"$GITHUB_BASE_REF"* ]]; then | ||
# Pull request event to a main branch | ||
echo "main_branch_affected=true" >> $GITHUB_OUTPUT | ||
elif [ "${{ inputs.event_name }}" != "pull_request" ] && [[ "${{ inputs.main_branches }}" == *"$GITHUB_REF_NAME"* ]]; then | ||
# Non pull request event to a main branch | ||
echo "main_branch_affected=true" >> $GITHUB_OUTPUT | ||
else | ||
# All other cases | ||
echo "main_branch_affected=false" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Invalidate cache on workflow_dispatch | ||
id: cache_version | ||
shell: bash | ||
run: | | ||
if [ "${{ inputs.event_name }}" == "workflow_dispatch" ] ; then | ||
echo "cache_version=0" >> $GITHUB_OUTPUT | ||
else | ||
echo "cache_version=1" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Report triggers | ||
run: | | ||
echo "R/ directory changes: ${{ steps.changed-files-yaml.outputs.R_any_changed }}" | ||
echo "tests/ directory changes: ${{ steps.changed-files-yaml.outputs.test_any_changed }}" | ||
echo "man/ directory changes: ${{ steps.changed-files-yaml.outputs.man_any_changed }}" | ||
echo "vignettes/ directory changes: ${{ steps.changed-files-yaml.outputs.vignette_any_changed }}" | ||
echo "README.Rmd changed: ${{ steps.changed-files-yaml.outputs.readme_any_changed }}" | ||
echo "DESCRIPTION changed: ${{ steps.changed-files-yaml.outputs.description_any_changed }}" | ||
echo "main branch affected: ${{ steps.main_branch_affected.outputs.main_branch_affected }}" | ||
echo "branch name: ${{ steps.branch_name.outputs.branch_name }}" | ||
echo "cache_version: ${{ steps.cache_version.outputs.cache_version }}" | ||
lint: | ||
needs: trigger | ||
uses: ./.github/workflows/lint.yaml | ||
with: | ||
run: ${{ !contains(inputs.skip, 'lint') && ( | ||
inputs.event_name == 'workflow_dispatch' || ( | ||
needs.trigger.outputs.R_files_changed == 'true' || | ||
needs.trigger.outputs.test_files_changed == 'true' || | ||
needs.trigger.outputs.man_files_changed == 'true' || | ||
needs.trigger.outputs.vignette_files_changed == 'true')) }} | ||
spell-checker: | ||
needs: trigger | ||
uses: ./.github/workflows/spell-checker.yaml | ||
with: | ||
run: ${{ !contains(inputs.skip, 'spell-checker') && ( | ||
inputs.event_name == 'workflow_dispatch' || ( | ||
needs.trigger.outputs.description_changed == 'true' || | ||
needs.trigger.outputs.man_files_changed == 'true' || | ||
needs.trigger.outputs.vignette_files_changed == 'true')) }} | ||
secrets: inherit | ||
R-CMD-check: | ||
needs: trigger | ||
uses: ./.github/workflows/R-CMD-check.yaml | ||
with: | ||
rcmdcheck_args: ${{ inputs.rcmdcheck_args }} | ||
cache_version: ${{ needs.trigger.outputs.cache_version }} | ||
run: ${{ !contains(inputs.skip, 'R-CMD-check') && ( | ||
inputs.event_name == 'workflow_dispatch' || ( | ||
needs.trigger.outputs.main_branch_affected == 'true' && ( | ||
needs.trigger.outputs.R_files_changed == 'true' || | ||
needs.trigger.outputs.test_files_changed == 'true' || | ||
needs.trigger.outputs.description_changed == 'true' || | ||
needs.trigger.outputs.man_files_changed == 'true' || | ||
needs.trigger.outputs.vignette_files_changed == 'true'))) }} | ||
secrets: inherit | ||
concurrency: | ||
group: R-CMD-check-${{ needs.trigger.outputs.branch_name }} | ||
cancel-in-progress: true | ||
code-coverage: | ||
needs: trigger | ||
uses: ./.github/workflows/code-coverage.yaml | ||
with: | ||
cache_version: ${{ needs.trigger.outputs.cache_version }} | ||
run: ${{ !contains(inputs.skip, 'code-coverage') && ( | ||
inputs.event_name == 'workflow_dispatch' || ( | ||
needs.trigger.outputs.main_branch_affected == 'true' && ( | ||
needs.trigger.outputs.R_files_changed == 'true' || | ||
needs.trigger.outputs.test_files_changed == 'true' || | ||
needs.trigger.outputs.description_changed == 'true'))) }} | ||
schemas: ${{ inputs.schemas }} | ||
backend_exclude: ${{ inputs.backend_exclude }} | ||
secrets: inherit | ||
concurrency: | ||
group: code-coverage-${{ needs.trigger.outputs.branch_name }} | ||
cancel-in-progress: true | ||
pkgdown: | ||
needs: trigger | ||
uses: ./.github/workflows/pkgdown.yaml | ||
with: | ||
event_name: ${{ inputs.event_name }} | ||
run_id: ${{ inputs.run_id }} | ||
run: ${{ !contains(inputs.skip, 'pkgdown') && ( | ||
inputs.event_name == 'workflow_dispatch' || ( | ||
(needs.trigger.outputs.main_branch_affected == 'true' || inputs.event_name == 'release') && ( | ||
needs.trigger.outputs.R_files_changed == 'true' || | ||
needs.trigger.outputs.description_changed == 'true' || | ||
needs.trigger.outputs.man_files_changed == 'true' || | ||
needs.trigger.outputs.vignette_files_changed == 'true'))) }} | ||
secrets: inherit | ||
concurrency: | ||
group: pkgdown-${{ needs.trigger.outputs.branch_name }} | ||
cancel-in-progress: true | ||
push-jobs: | ||
needs: trigger | ||
secrets: inherit | ||
concurrency: | ||
group: push-${{ needs.trigger.outputs.branch_name }} | ||
steps: | ||
- name: document | ||
uses: ./.github/workflows/document.yaml | ||
with: | ||
run: ${{ !contains(inputs.skip, 'document') && ( | ||
inputs.event_name == 'workflow_dispatch' || ( | ||
needs.trigger.outputs.R_files_changed == 'true' || | ||
needs.trigger.outputs.description_changed == 'true')) }} | ||
branch_name: ${{ needs.trigger.outputs.branch_name }} | ||
- name: render-readme: | ||
uses: ./.github/workflows/render-readme.yaml | ||
with: | ||
run: ${{ !contains(inputs.skip, 'render-readme') && ( | ||
inputs.event_name == 'workflow_dispatch' || | ||
needs.trigger.outputs.readme_files_changed == 'true') }} | ||
branch_name: ${{ needs.trigger.outputs.branch_name }} | ||
- name: update-lockfile: | ||
uses: ./.github/workflows/update-lockfile.yaml | ||
with: | ||
cache_version: ${{ needs.trigger.outputs.cache_version }} | ||
run: ${{ !contains(inputs.skip, 'update-lockfile') && ( | ||
inputs.event_name == 'workflow_dispatch' || ( | ||
needs.trigger.outputs.main_branch_affected == 'true' && ( | ||
needs.trigger.outputs.R_files_changed == 'true' || | ||
needs.trigger.outputs.test_files_changed == 'true' || | ||
needs.trigger.outputs.description_changed == 'true'))) }} | ||
branch_name: ${{ needs.trigger.outputs.branch_name }} |