|
| 1 | +# SPDX-License-Identifier: AGPL-3.0-or-later |
1 | 2 | name: CI |
2 | 3 |
|
3 | 4 | on: |
|
6 | 7 | pull_request: |
7 | 8 | branches: [ main ] |
8 | 9 |
|
9 | | -jobs: |
10 | | - test-python: |
11 | | - runs-on: ubuntu-latest |
12 | | - strategy: |
13 | | - matrix: |
14 | | - python-version: ['3.8', '3.9', '3.10', '3.11'] |
15 | | - |
16 | | - steps: |
17 | | - - uses: actions/checkout@v3 |
18 | | - |
19 | | - - name: Set up Python ${{ matrix.python-version }} |
20 | | - uses: actions/setup-python@v4 |
21 | | - with: |
22 | | - python-version: ${{ matrix.python-version }} |
23 | | - |
24 | | - - name: Install dependencies |
25 | | - run: | |
26 | | - python -m pip install --upgrade pip |
27 | | - pip install -e ".[dev]" |
28 | | -
|
29 | | - - name: Lint with flake8 |
30 | | - run: | |
31 | | - flake8 src/python/ipv6tools --count --select=E9,F63,F7,F82 --show-source --statistics |
32 | | - flake8 src/python/ipv6tools --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
33 | | -
|
34 | | - - name: Run tests with pytest |
35 | | - run: | |
36 | | - pytest tests/python/ -v --cov=ipv6tools --cov-report=xml --cov-report=term |
37 | | -
|
38 | | - - name: Upload coverage to Codecov |
39 | | - uses: codecov/codecov-action@v3 |
40 | | - with: |
41 | | - file: ./coverage.xml |
42 | | - flags: python |
43 | | - name: python-${{ matrix.python-version }} |
44 | | - |
45 | | - test-go: |
46 | | - runs-on: ubuntu-latest |
47 | | - strategy: |
48 | | - matrix: |
49 | | - go-version: ['1.20', '1.21'] |
50 | | - |
51 | | - steps: |
52 | | - - uses: actions/checkout@v3 |
53 | | - |
54 | | - - name: Set up Go ${{ matrix.go-version }} |
55 | | - uses: actions/setup-go@v4 |
56 | | - with: |
57 | | - go-version: ${{ matrix.go-version }} |
58 | | - |
59 | | - - name: Build Go tools |
60 | | - run: | |
61 | | - cd src/go |
62 | | - go build -v ./cmd/ipv6-ping |
63 | | - go build -v ./cmd/ipv6-scan |
64 | | -
|
65 | | - - name: Run Go tests |
66 | | - run: | |
67 | | - cd src/go |
68 | | - go test -v ./... |
69 | | -
|
70 | | - test-web: |
71 | | - runs-on: ubuntu-latest |
72 | | - |
73 | | - steps: |
74 | | - - uses: actions/checkout@v3 |
75 | | - |
76 | | - - name: Validate HTML |
77 | | - run: | |
78 | | - docker run --rm -v $(pwd)/src/web:/web ghcr.io/validator/validator:latest \ |
79 | | - vnu --also-check-css --also-check-svg /web/index.html || true |
80 | | -
|
81 | | - - name: Check JavaScript syntax |
82 | | - uses: actions/setup-node@v3 |
83 | | - with: |
84 | | - node-version: '18' |
85 | | - |
86 | | - - name: Lint JavaScript |
87 | | - run: | |
88 | | - cd src/web |
89 | | - npx jshint ipv6-tools.js app.js || true |
| 10 | +permissions: read-all |
90 | 11 |
|
| 12 | +jobs: |
91 | 13 | lint-shell: |
92 | 14 | runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + contents: read |
93 | 17 |
|
94 | 18 | steps: |
95 | | - - uses: actions/checkout@v3 |
| 19 | + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 |
96 | 20 |
|
97 | 21 | - name: Run ShellCheck |
98 | | - uses: ludeeus/action-shellcheck@master |
| 22 | + uses: ludeeus/action-shellcheck@00cae500b08a931fb5698e11e79bfbd38e612a38 # v2.0.0 |
99 | 23 | with: |
100 | 24 | scandir: './src/scripts' |
101 | 25 |
|
102 | | - docker-build: |
103 | | - runs-on: ubuntu-latest |
104 | | - |
105 | | - steps: |
106 | | - - uses: actions/checkout@v3 |
107 | | - |
108 | | - - name: Build Docker image |
109 | | - run: | |
110 | | - docker build -t ipv6-only:test . |
111 | | -
|
112 | | - - name: Test Docker image |
113 | | - run: | |
114 | | - docker run --rm ipv6-only:test ipv6-validate 2001:db8::1 |
115 | | -
|
116 | | - security: |
| 26 | + container-build: |
117 | 27 | runs-on: ubuntu-latest |
| 28 | + permissions: |
| 29 | + contents: read |
118 | 30 |
|
119 | 31 | steps: |
120 | | - - uses: actions/checkout@v3 |
121 | | - |
122 | | - - name: Run Bandit security scan |
123 | | - run: | |
124 | | - pip install bandit |
125 | | - bandit -r src/python/ipv6tools/ -f json -o bandit-report.json || true |
126 | | -
|
127 | | - - name: Run Safety check |
128 | | - run: | |
129 | | - pip install safety |
130 | | - safety check --json || true |
131 | | -
|
132 | | - release: |
133 | | - runs-on: ubuntu-latest |
134 | | - needs: [test-python, test-go, test-web, lint-shell] |
135 | | - if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
136 | | - |
137 | | - steps: |
138 | | - - uses: actions/checkout@v3 |
139 | | - |
140 | | - - name: Set up Python |
141 | | - uses: actions/setup-python@v4 |
142 | | - with: |
143 | | - python-version: '3.11' |
144 | | - |
145 | | - - name: Build package |
146 | | - run: | |
147 | | - pip install build |
148 | | - python -m build |
149 | | -
|
150 | | - - name: Publish to PyPI |
151 | | - if: startsWith(github.ref, 'refs/tags') |
152 | | - uses: pypa/gh-action-pypi-publish@release/v1 |
153 | | - with: |
154 | | - password: ${{ secrets.PYPI_API_TOKEN }} |
| 32 | + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 |
| 33 | + |
| 34 | + - name: Build container image with nerdctl/podman |
| 35 | + run: | |
| 36 | + if command -v nerdctl &> /dev/null; then |
| 37 | + nerdctl build -t ipv6-only:test -f Containerfile . |
| 38 | + elif command -v podman &> /dev/null; then |
| 39 | + podman build -t ipv6-only:test -f Containerfile . |
| 40 | + else |
| 41 | + echo "No supported container runtime found (nerdctl/podman)" |
| 42 | + exit 0 |
| 43 | + fi |
0 commit comments