Skip to content

Commit 4fa470b

Browse files
Update workflows: enhance cleanup job, add permissions, and improve vulnerability scan logic
Signed-off-by: kmilo <kmilo.denis.glez@yandex.com>
1 parent a0c59d3 commit 4fa470b

7 files changed

Lines changed: 45 additions & 39 deletions

File tree

‎.github/workflows/cleanup.yml‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ name: Cleanup Old Workflow Runs
22

33
on:
44
schedule:
5-
# Run daily at 2 AM UTC
65
- cron: '0 2 * * *'
76
workflow_dispatch:
87
inputs:
@@ -14,7 +13,7 @@ on:
1413
jobs:
1514
cleanup:
1615
runs-on: ubuntu-latest
17-
timeout-minutes: 20
16+
timeout-minutes: 30
1817
concurrency:
1918
group: workflow-cleanup
2019
cancel-in-progress: false
@@ -41,6 +40,7 @@ jobs:
4140
});
4241
4342
let deletedCount = 0;
43+
let failedCount = 0;
4444
for (const workflow of workflows) {
4545
const runs = await github.paginate(github.rest.actions.listWorkflowRuns, {
4646
owner,
@@ -60,9 +60,10 @@ jobs:
6060
await github.rest.actions.deleteWorkflowRun({ owner, repo, run_id: run.id });
6161
deletedCount++;
6262
} catch (error) {
63+
failedCount++;
6364
console.log(`Failed to delete run ${run.id}: ${error.message}`);
6465
}
6566
}
6667
}
6768
68-
console.log(`Deleted ${deletedCount} workflow runs`);
69+
console.log(`Deleted ${deletedCount} workflow runs, ${failedCount} failures`);

‎.github/workflows/pull_request.yml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
- main
77
workflow_dispatch:
88

9+
permissions:
10+
contents: read
11+
912
concurrency:
1013
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
1114
cancel-in-progress: true
@@ -18,7 +21,7 @@ jobs:
1821
uses: ./.github/workflows/scan.yml
1922

2023
pull-request:
21-
needs: test
24+
needs: [test, scan]
2225
name: Pull request success
2326
runs-on: ubuntu-latest
2427
steps:

‎.github/workflows/push.yml‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Copyright the Hyperledger Fabric contributors. All rights reserved.
2-
# SPDX-License-Identifier: Apache-2.0
3-
41
name: Push
52

63
on:
@@ -9,6 +6,12 @@ on:
96
- main
107
workflow_dispatch:
118

9+
permissions:
10+
contents: read
11+
1212
jobs:
1313
test:
14-
uses: ./.github/workflows/test.yaml
14+
uses: ./.github/workflows/test.yaml
15+
16+
scan:
17+
uses: ./.github/workflows/scan.yml

‎.github/workflows/release.yml‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ on:
99

1010
permissions:
1111
contents: read
12-
packages: write
1312

1413
jobs:
1514
release:
1615
runs-on: ubuntu-latest
16+
timeout-minutes: 20
1717
permissions:
1818
contents: read
19-
packages: write
2019

2120
steps:
2221
- uses: actions/checkout@v4
@@ -32,16 +31,16 @@ jobs:
3231
- name: Install build dependencies
3332
run: |
3433
python -m pip install --upgrade pip
35-
pip install build setuptools wheel
34+
python -m pip install build setuptools wheel
3635
3736
- name: Build distribution
38-
run: |
39-
python -m build --sdist --wheel
37+
run: python -m build --sdist --wheel
4038

39+
# Recommended future improvement: migrate to Trusted Publishing (OIDC).
40+
# Requires: permissions: id-token: write, remove 'password',
41+
# and configure the publisher on pypi.org.
4142
- name: Publish to PyPI
4243
if: startsWith(github.ref, 'refs/tags/')
4344
uses: pypa/gh-action-pypi-publish@release/v1
4445
with:
45-
password: ${{ secrets.PYPI_API_TOKEN }}
46-
repository: ${{ github.repository }}
47-
skip_existing_packages: true
46+
password: ${{ secrets.PYPI_API_TOKEN }}

‎.github/workflows/scan.yml‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ permissions:
1515
jobs:
1616
scan:
1717
runs-on: ubuntu-latest
18+
timeout-minutes: 15
19+
1820
steps:
1921
- uses: actions/checkout@v4
2022
with:
@@ -27,13 +29,16 @@ jobs:
2729
python-version: '3.11'
2830
cache: 'pip'
2931

30-
- name: Install dependencies for scanning
32+
- name: Install project dependencies
3133
run: |
3234
python -m pip install --upgrade pip
33-
python -m pip install safety
35+
python -m pip install -r requirements.txt
36+
37+
- name: Install pip-audit
38+
run: python -m pip install pip-audit
3439

35-
- name: Scan dependencies
36-
run: safety check --full-report
40+
- name: Audit requirements.txt
41+
run: pip-audit -r requirements.txt
3742

38-
- name: Scan source code
39-
run: safety check -r requirements.txt
43+
- name: Audit installed environment
44+
run: pip-audit

‎.github/workflows/test.yaml‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
1-
# Copyright the Hyperledger Fabric contributors. All rights reserved.
2-
# SPDX-License-Identifier: Apache-2.0
3-
41
name: Test
52

63
on:
7-
pull_request:
8-
branches:
9-
- main
10-
push:
11-
branches:
12-
- main
134
workflow_call:
145

15-
concurrency:
16-
group: ${{ github.workflow }}-${{ github.ref }}
17-
cancel-in-progress: true
18-
196
permissions:
207
contents: read
218

@@ -41,5 +28,4 @@ jobs:
4128
python -m pip install -r requirements.txt pytest pytest-asyncio
4229
4330
- name: Run tests
44-
run: |
45-
python -m pytest -q
31+
run: python -m pytest -q

‎.github/workflows/vulnerability-scan.yml‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Security vulnerability scan"
1+
name: "Scheduled vulnerability scan"
22

33
on:
44
schedule:
@@ -12,11 +12,20 @@ jobs:
1212
latest-release-version:
1313
name: Get latest release tag
1414
runs-on: ubuntu-latest
15+
timeout-minutes: 5
1516
outputs:
1617
tag_name: ${{ steps.tag-name.outputs.value }}
1718
steps:
1819
- id: tag-name
19-
run: echo "value=$(curl --location --silent --fail "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/latest" | jq --raw-output '.tag_name')" >> "${GITHUB_OUTPUT}"
20+
env:
21+
GH_TOKEN: ${{ github.token }}
22+
run: |
23+
tag="$(gh api "repos/${GITHUB_REPOSITORY}/releases/latest" --jq '.tag_name')"
24+
if [ -z "${tag}" ] || [ "${tag}" = "null" ]; then
25+
echo "::error::No releases found in ${GITHUB_REPOSITORY}"
26+
exit 1
27+
fi
28+
echo "value=${tag}" >> "${GITHUB_OUTPUT}"
2029
2130
scan:
2231
name: Scan ${{ needs.latest-release-version.outputs.tag_name }}

0 commit comments

Comments
 (0)