Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI tests using virtual cards #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading