Fix code scanning alert no. 49: Arbitrary file access during archive … #811
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: Test | |
on: | |
workflow_dispatch: | |
push: | |
branches: [main] | |
pull_request: | |
paths: | |
- .github/workflows/test.yml | |
- cmd/**/*.go | |
- testdata/**/* | |
- makefile | |
- .golangci.yml | |
- go.mod | |
- go.sum | |
workflow_call: | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
# Declare default permissions as read only. | |
permissions: read-all | |
jobs: | |
lint: | |
name: Lint | |
timeout-minutes: 10 | |
runs-on: ubuntu-latest | |
steps: | |
- name: Harden Runner | |
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 | |
with: | |
egress-policy: audit | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: Install Go | |
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 | |
with: | |
go-version-file: go.mod | |
check-latest: true | |
- uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1 | |
with: | |
version: latest | |
format: | |
name: Format | |
runs-on: ubuntu-latest | |
steps: | |
- name: Harden Runner | |
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 | |
with: | |
egress-policy: audit | |
- name: Check out repository code | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: Install Go | |
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 | |
with: | |
go-version-file: go.mod | |
check-latest: true | |
- name: Check formatting | |
run: | | |
make format-check | |
vulnerability-check: | |
name: "Vulnerability check" | |
runs-on: ubuntu-latest | |
steps: | |
- name: Harden Runner | |
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 | |
with: | |
egress-policy: audit | |
- name: Scan for Vulnerabilities | |
uses: golang/govulncheck-action@b625fbe08f3bccbe446d94fbf87fcc875a4f50ee # v1.0.4 | |
with: | |
go-version-file: go.mod | |
check-latest: true | |
go-package: ./... | |
# Make sure local_repository.pidx is linted against PackIndex.xsd | |
xmllint: | |
name: Xmllint | |
runs-on: ubuntu-latest | |
steps: | |
- name: Harden Runner | |
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 | |
with: | |
egress-policy: audit | |
- name: Check out repository code | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: Install Go | |
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 | |
with: | |
go-version-file: go.mod | |
check-latest: true | |
- name: Install xmllint | |
run: sudo apt-get update && sudo apt-get install libxml2-utils | |
- name: Check if local_repository.pidx is valid | |
run: | | |
make test-xmllint-localrepository | |
test-amd64: | |
strategy: | |
matrix: | |
# Tests on Mac are currently broken | |
goos: [windows, linux, darwin] | |
include: | |
- goos: windows | |
runs-on: windows-latest | |
- goos: linux | |
runs-on: ubuntu-latest | |
- goos: darwin | |
runs-on: macos-latest | |
name: "${{ matrix.goos }} | amd64" | |
runs-on: ${{ matrix.runs-on }} | |
steps: | |
- name: Harden Runner | |
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 | |
with: | |
egress-policy: audit | |
- name: Check out repository code | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: Install Go | |
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 | |
with: | |
go-version-file: go.mod | |
check-latest: true | |
- name: Install go-junit-report | |
run: go install github.com/jstemmer/go-junit-report/v2@14d61e6e75e3f3c74551d757ad936e8e88014464 # v2.1.0 | |
- name: Run unit tests | |
run: | | |
mkdir -p build | |
make test > build/cpackgettests-${{ matrix.goos }}-amd64.txt | |
- name: Generate JUnit test report | |
if: always() | |
run: | | |
go-junit-report -set-exit-code -in build/cpackgettests-${{ matrix.goos }}-amd64.txt -iocopy -out build/cpackget-testreport-${{ matrix.goos }}-amd64.xml | |
- name: Publish coverage report to Code Climate | |
if: ${{ startsWith(matrix.runs-on, 'ubuntu') && (github.workflow != 'Release') }} | |
uses: paambaati/codeclimate-action@f429536ee076d758a24705203199548125a28ca7 # v9.0.0 | |
env: | |
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} | |
with: | |
debug: true | |
coverageLocations: ./cover.out:gocov | |
prefix: github.com/open-cmsis-pack/cpackget | |
- name: Archive unit test results | |
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 | |
with: | |
name: test-results-${{ matrix.goos }}-amd64 | |
path: ./build/cpackget-testreport-${{ matrix.goos }}-amd64.xml | |
if-no-files-found: error | |
test-linux-arm64: | |
name: "linux | arm64" | |
runs-on: ubuntu-latest | |
steps: | |
- name: Harden Runner | |
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 | |
with: | |
egress-policy: audit | |
- name: Unit testing | |
uses: uraimo/run-on-arch-action@ac33288c3728ca72563c97b8b88dda5a65a84448 # v2 | |
with: | |
arch: aarch64 | |
distro: ubuntu_latest | |
env: | | |
GIT_DISCOVERY_ACROSS_FILESYSTEM: 1 | |
install: | | |
apt-get update -qq -y | |
apt-get install -qq -y software-properties-common git make | |
add-apt-repository -y ppa:longsleep/golang-backports | |
apt-get update -qq -y | |
apt-get install -qq -y golang-1.22 | |
setup: | | |
mkdir -p "${PWD}/artifacts" | |
dockerRunArgs: | | |
--volume "${PWD}/artifacts:/artifacts" | |
run: | | |
export PATH=$PATH:/usr/lib/go-1.22/bin | |
git clone --depth 1 ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} | |
cd cpackget | |
git fetch --depth 1 origin ${GITHUB_REF} | |
git checkout FETCH_HEAD | |
mkdir -p build | |
make test > build/cpackgettests-linux-arm64.txt | |
cp build/cpackgettests-linux-arm64.txt "/artifacts/cpackgettests-linux-arm64.txt" | |
- name: Install Go | |
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 | |
with: | |
go-version: '1.22' | |
check-latest: true | |
- name: Install go-junit-report | |
run: go install github.com/jstemmer/go-junit-report/v2@14d61e6e75e3f3c74551d757ad936e8e88014464 # v2.1.0 | |
- name: Generate JUnit test report | |
run: | | |
go-junit-report -set-exit-code -in ${PWD}/artifacts/cpackgettests-linux-arm64.txt -iocopy -out ./cpackget-testreport-linux-arm64.xml | |
- name: Archive unit test results | |
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 | |
with: | |
name: test-results-linux-arm64 | |
path: ./cpackget-testreport-linux-arm64.xml | |
if-no-files-found: error |