Skip to content

Feat/ci as a state of the art part 4 #88

Feat/ci as a state of the art part 4

Feat/ci as a state of the art part 4 #88

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@de90cc6fb38fc0963ad72b210f1f284cd68cea36 #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-or-retag-go-projects:
needs: [ check-permissions, projects-changed ]
strategy:
matrix:
go-component: ${{ fromJson('["gh-action", "history-exporter"]') }}
uses: ./.github/workflows/50_go_build-component.yml
secrets: inherit
name: 'Build: ${{ matrix.go-component }}'
with:
cmd-path: './cmd/${{ matrix.go-component }}'
base-sha: ${{ github.event.pull_request.base.sha }}
head-sha: ${{ github.event.pull_request.head.sha }}
docker-image-base: neondatabase/${{ matrix.go-component }}
retag-base-image: ${{ contains(needs.projects-changed.outputs.cmd-unchanged, matrix.go-component) }}
run-build: ${{ contains(needs.projects-changed.outputs.cmd-changes, matrix.go-component) }}
pack-to-docker-image: true
test-go-projects:
needs: [ check-permissions, projects-changed ]
strategy:
matrix:
go-component: ${{ fromJson('["gh-action", "history-exporter"]') }}
uses: ./.github/workflows/50_go_test-component.yml
secrets: inherit
name: 'Unit Tests: ${{ matrix.go-component }}'
with:
cmd-path: './cmd/${{ matrix.go-component }}'
base-sha: ${{ github.event.pull_request.base.sha }}
head-sha: ${{ github.event.pull_request.head.sha }}
e2e-tests:
needs: [ build-or-retag-go-projects ]
runs-on: [ self-hosted, small ]
steps:
- run: |
echo "Running e2e tests"
conclusion:
needs: [ test-go-projects, e2e-tests ]
if: ${{ always() }}
runs-on: [ self-hosted, small ]
env:
GO_TESTS_RESULT: ${{ needs.test-go-projects.result }}
E2E_TESTS_RESULT: ${{ needs.e2e-tests.result }}
steps:
- name: Print final message
run: |
echo Thats it.
echo "We can add here labels to PR to make it visible if any parts are failing"
- name: Conclusion
run: |
exit_code=0
if [ "${GO_TESTS_RESULT}" != "success" ]; then exit_code=$(( exit_code + 1 )); fi
if [ "${E2E_TESTS_RESULT}" != "success" ]; then exit_code=$(( exit_code + 2 )); fi
exit "${exit_code}"