Webassembly day11 #883
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
--- | |
# | |
# .github/workflows/go.yml | |
# | |
name: Go Workflow 4.0 | |
on: # yamllint disable-line rule:truthy | |
pull_request: | |
workflow_dispatch: | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
stage1: | |
name: Change Check | |
runs-on: 'ubuntu-latest' | |
outputs: | |
docs_changed: ${{ steps.check_file_changed.outputs.docs_changed }} | |
matrix_exercise: ${{ steps.check_file_changed.outputs.matrix_exercise }} | |
exercise_count: ${{ steps.check_file_changed.outputs.exercise_count }} | |
steps: | |
- name: Check GitHub Vars | |
id: github-vars | |
run: set | grep -e ^CI -e ^GITHUB_ -e ^RUNNER_ | |
- name: Checkout Repo | |
id: checkout-repo | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.ref }} | |
submodules: recursive | |
- name: Get Change List | |
id: check_file_changed | |
run: |- | |
{ | |
printf "Workflow: %s\n\n" "${GITHUB_WORKFLOW}" | |
printf "Runner: name[%s] arch[%s]\n" "${RUNNER_NAME}" "${RUNNER_ARCH}" | |
printf "Repo: %s\n" "${GITHUB_REPOSITORY}" | |
printf "User: %s\n" "${GITHUB_TRIGGERING_ACTOR}" | |
printf "\n" | |
} | tee -a "${GITHUB_STEP_SUMMARY}" | |
# get user info for default gh container | |
{ | |
printf "\`\`\`text\n" | |
printf "Container user info:\n" | |
who | |
printf "\n" | |
id | |
printf "\`\`\`\n" | |
} | tee -a "${GITHUB_STEP_SUMMARY}" | |
printf "\n" | |
# Diff HEAD with the previous commit then output to stdout. | |
GIT_DIFF="$(git diff --name-only HEAD^ HEAD | tee /tmp/changed_files.txt)" | |
{ | |
printf "=== Which files changed? ===\n" | |
printf "\`\`\`text\n" | |
printf "%s\n" "${GIT_DIFF}" | |
printf "\`\`\`\n" | |
} | tee -a "${GITHUB_STEP_SUMMARY}" | |
HAS_WF_DIFF=false | |
HAS_EX_DIFF=false | |
if printf "%s\n" "${GIT_DIFF}" | grep -E '^(.github/workflows/go.yml|.github/citools/go/)$'; then | |
HAS_WF_DIFF=true | |
fi | |
if printf "%s\n" "${GIT_DIFF}" | grep -E '^(go/.*[.]go|go/.*/go[.](sum|mod))$'; then | |
HAS_EX_DIFF=true | |
fi | |
printf "\n" | |
printf "=== Did WF/CI change without exercise changes? ===\n" | |
CI_FORCE_FULL=false | |
if ${HAS_WF_DIFF} && ! ${HAS_EX_DIFF}; then | |
CI_FORCE_FULL=true | |
printf "%s\n" "${CI_FORCE_FULL}" | |
fi | |
printf "\n" | |
# Get changed exercise list. | |
if [[ ${GITHUB_EVENT_NAME} == pull_request ]] && ! ${CI_FORCE_FULL}; then | |
printf "Generating pull request changed exercise list.\n" | |
grep -E '^go/[-a-z0-9]+./.*$' /tmp/changed_files.txt | cut -f1,2 -d/ | sort -Vu | tee /tmp/exercises.txt || true | |
else | |
printf "Generating complete exercise list.\n" | |
find ./go/ -type d -print | grep -v -E '^[.]/go/(|[.].*)$' | sed -r -e 's:[.]/(go/[-a-z0-9]+)/?.*$:\1:g' | sort -Vu | tee /tmp/exercises.txt | |
HAS_DIFF=true | |
fi | |
printf "\n" | |
# Check if the files are present in the changed file list (added, modified, deleted) then output to stdout. | |
HAS_DIFF="${HAS_DIFF:-false}" | |
printf "=== Which Golang files changed? ===\n" | |
if printf "%s\n" "${GIT_DIFF}" | grep -E '^(go/.*[.]go|go/.*/go[.](sum|mod)|.github/workflows/go.yml)'; then | |
HAS_DIFF=true | |
printf "%s\n" "${HAS_DIFF}" | |
fi | |
printf "\n" | |
# Did Golang files change? | |
printf "=== Did Golang files change? ===\n" | |
printf "%s\n" "${HAS_DIFF}" | |
printf "\n" | |
# Generate exercise job matrix from changed files list. | |
printf "=== Generating matrix exercise list. ===\n" | |
declare -i last=0 | |
declare -i count=0 | |
last=$(wc -l /tmp/exercises.txt | cut -f1 -d\ ) | |
((last -= 1)) || true | |
entries="" | |
while read -r line; do | |
if [[ ! ${count} -lt ${last} ]]; then | |
comma="" | |
else | |
comma="," | |
fi | |
printf -v entry "\"%s\"%s\n" "${line}" "${comma}" | |
((count += 1)) | |
entries+="${entry}" | |
done < <(sort -V /tmp/exercises.txt) | |
jq --sort-keys . >/tmp/exercises.json <<EOF | |
[ ${entries} ] | |
EOF | |
exercise_count="$(jq '. | length' /tmp/exercises.json)" | |
printf "%s=%s\n" "exercise_count" "${exercise_count}" | tee -a "${GITHUB_OUTPUT}" | |
matrix_exercise="$(jq --compact-output --sort-keys . /tmp/exercises.json)" | |
printf "%s=%s\n" "matrix_exercise" "${matrix_exercise}" | tee -a "${GITHUB_OUTPUT}" | |
printf "\n" | |
cat "${GITHUB_OUTPUT}" | |
# Don't run stage 2 if PR mode doesn't have testable changes. | |
if [[ ${GITHUB_EVENT_NAME} == pull_request ]] && [[ -z ${entries} ]]; then | |
printf "In PR mode with no testable changes, disabling stage 2.\n" | |
HAS_DIFF=false | |
fi | |
# Set the output named "docs_changed" | |
printf "%s=%s\n" "docs_changed" "${HAS_DIFF}" >> "${GITHUB_OUTPUT}" | |
check-matrix: | |
runs-on: ubuntu-latest | |
needs: stage1 | |
steps: | |
- name: Install json2yaml | |
run: sudo npm install -g json2yaml | |
- name: Check matrix::exercises | |
run: |- | |
exercise_count='${{ needs.stage1.outputs.exercise_count }}' | |
matrix_exercise='${{ needs.stage1.outputs.matrix_exercise }}' | |
{ | |
printf "\`\`\`text\n" | |
printf "exercise_count=%s\n" "${exercise_count}" | |
printf "matrix_exercise=%s\n" "${matrix_exercise}" | |
printf "\`\`\`\n" | |
printf "json:\n" | |
printf "\`\`\`text\n" | |
printf "%s" "${matrix_exercise}" | jq . | |
printf "\`\`\`\n" | |
} | tee -a "${GITHUB_STEP_SUMMARY}" | |
{ | |
printf "yaml:\n" | |
printf "\`\`\`text\n" | |
printf "{ \"matrix\": { \"exercise\": %s } }" "${matrix_exercise}" | json2yaml | |
printf "\`\`\`\n" | |
} | tee -a "${GITHUB_STEP_SUMMARY}" | |
stage2: | |
name: Go Checks | |
strategy: | |
matrix: | |
go-version: ["1.21"] | |
os: ["ubuntu-latest", "windows-latest", "macos-latest"] | |
exclude: | |
- os: "macos-latest" | |
go-version: "1.21" | |
- os: "windows-latest" | |
go-version: "1.21" | |
exercise: ${{fromJson(needs.stage1.outputs.matrix_exercise)}} | |
runs-on: "${{ matrix.os }}" | |
container: | |
image: vpayno/ci-generic-debian:latest | |
needs: [stage1] | |
if: needs.stage1.outputs.docs_changed == 'true' | |
steps: | |
- name: Checkout Repo (${{ matrix.go-version }}) [${{ matrix.exercise }}] | |
id: checkout-repo | |
uses: actions/checkout@v3 | |
- name: Go Setup (${{ matrix.go-version }}) [${{ matrix.exercise }}] | |
id: go-setup | |
run: |- | |
./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/go/go-setup-config | |
- name: Verify Go Verify (${{ matrix.go-version }}) [${{ matrix.exercise }}] | |
id: go-verify | |
run: |- | |
./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/go/go-setup-verify | |
- name: Show Dir Contents (${{ matrix.go-version }}) [${{ matrix.exercise }}] | |
id: cd-to-go-dir | |
run: |- | |
ls -lhva "./${{ matrix.exercise }}" | |
- name: Analysing the code with revive (${{ matrix.go-version }}) [${{ matrix.exercise }}] | |
id: go-revive | |
run: |- | |
./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/go/go-lint-revive | |
- name: Analysing the code with go vet (${{ matrix.go-version }}) [${{ matrix.exercise }}] | |
id: go-vet | |
run: |- | |
./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/go/go-lint-go_vet | |
- name: Testing with go test coverage (${{ matrix.go-version }}) [${{ matrix.exercise }}] | |
id: go-test-coverage | |
run: |- | |
./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/go/go-test-cover | |
- name: Testing with errcheck (${{ matrix.go-version }}) [${{ matrix.exercise }}] | |
id: go-test-errcheck | |
continue-on-error: true | |
run: |- | |
./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/go/go-lint-errcheck | |
- name: Testing with gocritic (${{ matrix.go-version }}) [${{ matrix.exercise }}] | |
id: go-test-gocritic | |
continue-on-error: true | |
run: |- | |
./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/go/go-lint-gocritic | |
- name: Testing with gocyclo (${{ matrix.go-version }}) [${{ matrix.exercise }}] | |
id: go-test-gocyclo | |
continue-on-error: true | |
run: |- | |
./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/go/go-lint-gocyclo | |
- name: Testing with golangci-lint (${{ matrix.go-version }}) [${{ matrix.exercise }}] | |
id: go-test-golangci-lint | |
continue-on-error: true | |
run: |- | |
./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/go/go-lint-golangci-lint | |
- name: Testing with go-consistent (${{ matrix.go-version }}) [${{ matrix.exercise }}] | |
id: go-test-go-consistent | |
continue-on-error: true | |
run: |- | |
./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/go/go-lint-go-consistent | |
- name: Testing with go-ineffassign (${{ matrix.go-version }}) [${{ matrix.exercise }}] | |
id: go-test-ineffassign | |
continue-on-error: true | |
run: |- | |
./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/go/go-lint-ineffassign | |
- name: Testing with staticcheck (${{ matrix.go-version }}) [${{ matrix.exercise }}] | |
id: go-test-staticcheck | |
continue-on-error: true | |
run: |- | |
./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/go/go-lint-staticcheck | |
- name: Testing with misspell (${{ matrix.go-version }}) [${{ matrix.exercise }}] | |
id: go-test-misspell | |
run: |- | |
./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/go/go-lint-misspell | |
- name: Testing with gosec (${{ matrix.go-version }}) [${{ matrix.exercise }}] | |
id: go-test-security | |
continue-on-error: true | |
run: |- | |
./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/go/go-lint-gosec |