Skip to content

Commit

Permalink
Add CI tests using virtual cards
Browse files Browse the repository at this point in the history
Signed-off-by: Steffen Vogel <[email protected]>
  • Loading branch information
stv0g committed Nov 8, 2023
1 parent 70b4f23 commit 2665653
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 30 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# SPDX-FileCopyrightText: 2023 Steffen Vogel <[email protected]>
# SPDX-License-Identifier: Apache-2.0

# yaml-language-server: $schema=https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/github-workflow.json
---
name: Build

on:
push:
branches:
- main
pull_request:

jobs:
build:
name: Build

runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macOS-latest, windows-latest ]

steps:
- uses: actions/checkout@v4

- name: Install dependencies
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install -y
libpcsclite-dev
pcscd
pcsc-tools

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
check-latest: true

- name: Lint
# TODO: golangci-lint v1.54 is currently broken on Windows?
if: matrix.os != 'windows-latest'
uses: golangci/golangci-lint-action@v3
with:
version: v1.54.0
continue-on-error: true

- name: Set up gotestfmt
run: go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest

- name: Run Go tests
if: matrix.os == 'ubuntu-latest'
shell: bash
run: |
set -euo pipefail
go test \
-v \
-json \
-coverpkg ./... \
-tags ci \
-coverprofile cover.profile \
./... 2>&1 | \
tee gotest.log | \
gotestfmt
- name: Upload test log
if: always() && matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v3
with:
name: test-log
path: gotest.log
if-no-files-found: error

- name: Build
if: matrix.os != 'ubuntu-latest'
run: go build .

- name: Report test coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: cover.profile
49 changes: 19 additions & 30 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

# SPDX-FileCopyrightText: 2023 Steffen Vogel <[email protected]>
# SPDX-License-Identifier: Apache-2.0

# yaml-language-server: $schema=https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/github-workflow.json
---
name: Build
name: Test with virtual cards

on:
push:
Expand All @@ -12,46 +13,43 @@ on:
pull_request:

jobs:
build:
name: Build

runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macOS-latest, windows-latest ]
test:
name: Test with Virtual Cards
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install dependencies
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install -y
libpcsclite-dev
pcscd
pcsc-tools

- name: Start card
run: docker run
--detach
--volume /run/pcscd:/run/pcscd
registry.gitlab.com/hkos/virtual-piv/openfips201
/bin/bash -c "bash /start.sh; sleep 10000"

- name: Check virtual card
run: |
sleep 5
pcsc_scan -vt2
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
check-latest: true

- name: Lint
# TODO: golangci-lint v1.54 is currently broken on Windows?
if: matrix.os != 'windows-latest'
uses: golangci/golangci-lint-action@v3
with:
version: v1.54.0
continue-on-error: true

- name: Set up gotestfmt
run: go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest

- name: Run Go tests
if: matrix.os == 'ubuntu-latest'
shell: bash
env:
TEST_DANGEROUS_WIPE_REAL_CARD: "1"
run: |
set -euo pipefail
go test \
Expand All @@ -71,12 +69,3 @@ jobs:
name: test-log
path: gotest.log
if-no-files-found: error

- name: Build
if: matrix.os != 'ubuntu-latest'
run: go build .

- name: Report test coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: cover.profile

0 comments on commit 2665653

Please sign in to comment.