Skip to content

Commit d231a5a

Browse files
committed
ci: split monolithic ci/cd workflow into two distinct workflows
- deleted ci.yml - added lint-and-test.yml for PR source branch testing - added release-and-publish.yml for changes on main When PR is opened, pr-title.yml will validate the PR title to ensure that squash merge does not break cz or PSR. When PR is opened/updated (code), lint-and-test.yml will lint and test the code in the source branch. When PR is merged to main, release-and-publish.yml will run on main.
1 parent 2e16061 commit d231a5a

2 files changed

Lines changed: 59 additions & 53 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Lint and Test
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
lint:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
python-version: ["3.11"] # TODO see https://github.com/mitre-attack/mitreattack-python/issues/176
16+
steps:
17+
- uses: actions/checkout@v6
18+
19+
- name: Install the latest version of uv
20+
uses: astral-sh/setup-uv@v7
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
24+
- name: Install dependencies
25+
run: uv sync --all-extras
26+
27+
- name: Lint with ruff
28+
run: uv run ruff check --output-format github
29+
30+
- name: Check formatting with ruff
31+
run: uv run ruff format --check
32+
33+
test:
34+
runs-on: ubuntu-latest
35+
strategy:
36+
matrix:
37+
python-version: ["3.11"] # TODO see https://github.com/mitre-attack/mitreattack-python/issues/176
38+
steps:
39+
- uses: actions/checkout@v6
40+
41+
- name: Install the latest version of uv
42+
uses: astral-sh/setup-uv@v7
43+
with:
44+
python-version: ${{ matrix.python-version }}
45+
46+
- name: Install dependencies
47+
run: uv sync --all-extras
48+
49+
- name: Run pytest
50+
run: uv run pytest --cov=mitreattack
Lines changed: 9 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
name: CI
1+
name: Release and Publish
22

33
on:
44
push:
55
branches: [main]
6-
pull_request:
7-
branches: [main]
86

97
permissions:
108
contents: read
@@ -13,7 +11,6 @@ jobs:
1311
# Validate the squash merge commit message on pushes to main.
1412
# PR title validation is handled separately in pr-title.yml.
1513
commitlint:
16-
if: github.event_name == 'push'
1714
runs-on: ubuntu-latest
1815
steps:
1916
- name: Checkout
@@ -34,60 +31,18 @@ jobs:
3431
- name: Validate commit message
3532
run: uv run cz check --rev-range HEAD~1..HEAD
3633

37-
lint:
38-
runs-on: ubuntu-latest
39-
strategy:
40-
matrix:
41-
python-version: ["3.11"] # TODO see https://github.com/mitre-attack/mitreattack-python/issues/176
42-
steps:
43-
- uses: actions/checkout@v6
44-
45-
- name: Install the latest version of uv
46-
uses: astral-sh/setup-uv@v7
47-
with:
48-
python-version: ${{ matrix.python-version }}
49-
50-
- name: Install dependencies
51-
run: uv sync --all-extras
52-
53-
- name: Lint with ruff
54-
run: uv run ruff check --output-format github
55-
56-
- name: Check formatting with ruff
57-
run: uv run ruff format --check
58-
59-
test:
60-
runs-on: ubuntu-latest
61-
strategy:
62-
matrix:
63-
python-version: ["3.11"] # TODO see https://github.com/mitre-attack/mitreattack-python/issues/176
64-
steps:
65-
- uses: actions/checkout@v6
66-
67-
- name: Install the latest version of uv
68-
uses: astral-sh/setup-uv@v7
69-
with:
70-
python-version: ${{ matrix.python-version }}
71-
72-
- name: Install dependencies
73-
run: uv sync --all-extras
74-
75-
# - name: Run pytest
76-
# run: uv run pytest --cov=mitreattack
77-
7834
release:
79-
needs: [commitlint, lint, test]
80-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
35+
needs: [commitlint]
8136
strategy:
8237
matrix:
8338
python-version: ["3.11"] # TODO see https://github.com/mitre-attack/mitreattack-python/issues/176
8439
runs-on: ubuntu-latest
8540
# The concurrency block prevents multiple release jobs from running simultaneously for the same branch.
86-
# This is particularly useful for releases since you typically want sequential deployments (finish
87-
# current release before starting next) rather than canceling in-progress releases or running them
41+
# This is particularly useful for releases since you typically want sequential deployments (finish
42+
# current release before starting next) rather than canceling in-progress releases or running them
8843
# in parallel.
8944
concurrency:
90-
# Creates a concurrency group keyed by workflow name + "release" + branch name (e.g., "Continuous Delivery-release-main")
45+
# Creates a concurrency group keyed by workflow name + "release" + branch name (e.g., "Release and Publish-release-main")
9146
group: ${{ github.workflow }}-release-${{ github.ref_name }}
9247
# If a release is already running and a new push triggers another, the new job waits rather than canceling the running one
9348
# If you changed cancel-in-progress to true, a new push would cancel the currently running release job.
@@ -159,11 +114,12 @@ jobs:
159114
needs: release
160115
if: needs.release.outputs.released == 'true'
161116
runs-on: ubuntu-latest
162-
environment: release
163-
117+
environment:
118+
name: release
119+
url: https://pypi.org/p/mitreattack-python
164120
permissions:
165121
contents: read
166-
id-token: write
122+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
167123

168124
steps:
169125
- name: Download build artifacts

0 commit comments

Comments
 (0)