CI as a state of the art, part 3 #65
Workflow file for this run
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: Pull Request Entry Point | |
on: | |
pull_request: | |
env: | |
list-of-all-components: "[ 'gh-action', 'history-exporter' ]" | |
jobs: | |
check-permissions: | |
if: ${{ !contains(github.event.pull_request.labels.*.name, 'run-no-ci') }} | |
uses: ./.github/workflows/90_helpers-check-permissions.yml | |
with: | |
github-event-name: ${{ github.event_name }} | |
workflows-sanity-checks: | |
needs: [ check-permissions ] | |
uses: ./.github/workflows/10_workflow-sanity-checks.yml | |
projects-changed: | |
needs: [ check-permissions, workflows-sanity-checks ] | |
name: Check source files for changes | |
runs-on: [ self-hosted, small ] | |
timeout-minutes: 2 | |
outputs: | |
go-projects-changes: ${{ steps.go-projects-changes.outputs.changes }} | |
go-mod-changes: ${{ steps.go-projects-changes.outputs.go-mod }} | |
common-libs-changes: ${{ steps.go-projects-changes.outputs.common-libs }} | |
cmd-changes: ${{ steps.per-component-changes.outputs.cmd-changes }} | |
tests-changes: ${{ steps.per-component-changes.outputs.tests-changes }} | |
cmd-unchanged: ${{ steps.per-component-changes.outputs.cmd-unchanged }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Go Projects Changes | |
id: go-projects-changes | |
uses: dorny/paths-filter@1441771bbfdd59dcd748680ee64ebd8faab1a242 #v3 | |
with: | |
token: ${{ github.token }} | |
filters: .github/file-filters/go-components.yaml | |
base: ${{ github.event_name != 'pull_request' && (github.event.merge_group.base_ref || github.ref_name) || '' }} | |
ref: ${{ github.event_name != 'pull_request' && (github.event.merge_group.head_ref || github.ref) || '' }} | |
- name: Check per-component changes | |
id: per-component-changes | |
env: | |
PR_PATHS_CHANGES: ${{ steps.go-projects-changes.outputs.changes }} | |
CMDS_LIST: '["gh-action", "history-exporter"]' | |
TESTS_LIST: '["gh-action-tests", "history-exporter-tests"]' | |
run: | | |
cmd_changes=$(\ | |
echo "$PR_PATHS_CHANGES" \ | |
| jq -c --argjson filter_list "$CMDS_LIST" \ | |
'.[] | select( [.] | inside($filter_list) )' \ | |
) | |
test_changes=$(\ | |
echo "$PR_PATHS_CHANGES" \ | |
| jq -c --argjson filter_list "$TESTS_LIST" \ | |
'.[] | select( [.] | inside($filter_list) )' \ | |
) | |
echo "cmd-changes=${cmd_changes}" >> "${GITHUB_OUTPUT}" | |
echo "test-changes=${test_changes}" >> "${GITHUB_OUTPUT}" | |
cmd_unchanged=$(jq -c -n --argjson full "$CMDS_LIST" --argjson changed "$PR_PATHS_CHANGES" \ | |
'[ $full[] | select(. as $item | all($changed[]; . != $item)) ]' \ | |
) | |
echo "cmd-unchanged=${cmd_unchanged}" >> "${GITHUB_OUTPUT}" | |
build-go-projects: | |
needs: [ check-permissions, projects-changed ] | |
if: needs.projects-changed.outputs.go-projects-changes != '[]' | |
strategy: | |
matrix: | |
go-component: ${{ fromJson(needs.projects-changed.outputs.go-projects-changes) }} | |
uses: ./.github/workflows/50_go_build-one-component.yml | |
secrets: inherit | |
name: 'Golang: ${{ matrix.go-component }}' | |
with: | |
component-name: ${{ matrix.go-component }} | |
base-sha: ${{ github.event.pull_request.base.sha }} | |
head-sha: ${{ github.event.pull_request.head.sha }} | |
pack-to-docker-image: true | |
reuse-unchanged-components: | |
runs-on: [ self-hosted, small ] | |
needs: [ check-permissions, projects-changed ] | |
if: needs.projects-changed.outputs.cmd-unchanged != '[]' | |
name: "Reuse unchanged components ${{ needs.projects-changed.outputs.cmd-unchanged }}" | |
steps: | |
- id: show-unchanged-list | |
env: | |
UNCHANGED: ${{ needs.projects-changed.outputs.cmd-unchanged }} | |
run: | | |
echo $UNCHANGED | |
final-step: | |
needs: [ build-go-projects ] | |
if: ${{ always() }} | |
runs-on: [ self-hosted, small ] | |
steps: | |
- name: Print final message | |
run: | | |
echo Thats it. |