Skip to content

Commit

Permalink
Merge pull request #2 from stfc/pass_with_doc
Browse files Browse the repository at this point in the history
ENH: Add check for doc or workflow label
  • Loading branch information
gmatthews20 authored Nov 14, 2024
2 parents f72383b + 8565e22 commit fce371a
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/self_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ jobs:
- name: Self test
if: ${{ github.ref != 'refs/heads/main' }}
id: selftest
uses: khalford/check-version-action@main
uses: stfc/check-version-action@main
with:
app_version_path: "version.txt"
docker_compose_path: "docker-compose.yml"
labels: ${{ toJSON(github.event.pull_request.labels.*.name) }}

- name: Log Success
if: ${{ env.app_updated == 'true' }}
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Read here for details: [Link to GitHub docs](https://docs.github.com/en/actions/
The release tag is extracted and stored in `$GITHUB_ENV`,
you can access this in your workflow with `$ {{ env.release_tag }}`

If you are making a change which should not affect the version such as README or CI changes. You can label the pull request with `documentation` or `workflow` and the version checks will be skipped.

<!-- start usage -->
```yaml
- name: Checkout main
Expand All @@ -43,12 +45,13 @@ you can access this in your workflow with `$ {{ env.release_tag }}`
# Don't run on main otherwise it will compare main with main
if: ${{ github.ref != 'refs/heads/main' }}
id: version_comparison
uses: khalford/check-version-action@main
uses: stfc/check-version-action@main
with:
# Path to version file from project root
app_version_path: "version.txt"
# Optional: To check if compose image version matches application version
docker_compose_path: "docker-compose.yaml"
labels: ${{ toJSON(github.event.pull_request.labels.*.name) }}

- name: Log App Success
if: ${{ env.app_updated == 'true' }}
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ inputs:
docker_compose_path:
description: 'Path to compose file.'
required: false
labels:
description: 'Labels added to pull requests.'
required: False
outputs:
app_updated:
description: 'If the app version was updated or not.'
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
services:
self-test:
image: some/test:1.0.0
image: some/test:1.1.0
7 changes: 6 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from comparison import CompareAppVersion, CompareComposeVersion


def main():
def main() -> bool:
"""
The entry point function for the action.
Here we get environment variables then set environment variables when finished.
Expand All @@ -18,6 +18,10 @@ def main():
with open(branch_path / app_path, "r", encoding="utf-8") as release_file:
release_version = release_file.read().strip("\n")

labels = os.environ.get("INPUT_LABELS")
if any(label in labels for label in ["documentation", "workflow"]):
return False

CompareAppVersion().run(main_path / app_path, branch_path / app_path)
if compose_path:
compose_path = Path(compose_path)
Expand All @@ -30,6 +34,7 @@ def main():
if compose_path:
env.write("compose_updated=true")
env.write(f"release_tag={release_version}")
return True


if __name__ == "__main__":
Expand Down
26 changes: 24 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@
@patch("main.os")
def test_main(mock_os, mock_compare_app, mock_compare_compose):
"""Test the main method runs correctly."""
mock_os.environ.get.side_effect = [Path("app"), Path("compose"), Path("workspace")]
mock_os.environ.get.side_effect = [
Path("app"),
Path("compose"),
Path("workspace"),
[],
]

with patch("builtins.open", mock_open(read_data="1.0.0")):
main()
res = main()
mock_os.environ.get.assert_any_call("INPUT_LABELS")
mock_os.environ.get.assert_any_call("INPUT_APP_VERSION_PATH")
mock_os.environ.get.assert_any_call("INPUT_DOCKER_COMPOSE_PATH")
mock_os.environ.get.assert_any_call("GITHUB_WORKSPACE")
Expand All @@ -24,3 +31,18 @@ def test_main(mock_os, mock_compare_app, mock_compare_compose):
mock_compare_compose.return_value.run.assert_called_once_with(
mock_branch_path / "app", mock_branch_path / "compose"
)
assert res


@patch("main.os")
def test_main_skip(mock_os):
"""Test the main method skips the comparison methods."""
mock_os.environ.get.side_effect = [
Path("app"),
Path("compose"),
Path("workspace"),
["workflow", "documentation"],
]
with patch("builtins.open", mock_open(read_data="1.0.0")):
res = main()
assert not res
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.1.0

0 comments on commit fce371a

Please sign in to comment.