diff --git a/.github/workflows/self_test.yaml b/.github/workflows/self_test.yaml index cfc1bfc..66a95dc 100644 --- a/.github/workflows/self_test.yaml +++ b/.github/workflows/self_test.yaml @@ -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' }} diff --git a/README.md b/README.md index 8a57c54..3dc6db7 100644 --- a/README.md +++ b/README.md @@ -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. + ```yaml - name: Checkout main @@ -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' }} diff --git a/action.yml b/action.yml index e65ec22..de10723 100644 --- a/action.yml +++ b/action.yml @@ -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.' diff --git a/docker-compose.yml b/docker-compose.yml index 9ede7c4..b8fb975 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,3 +1,3 @@ services: self-test: - image: some/test:1.0.0 + image: some/test:1.1.0 diff --git a/src/main.py b/src/main.py index 8286bb5..34cf5f4 100644 --- a/src/main.py +++ b/src/main.py @@ -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. @@ -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) @@ -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__": diff --git a/tests/test_main.py b/tests/test_main.py index 7aec16b..810f25a 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -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") @@ -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 diff --git a/version.txt b/version.txt index 3eefcb9..9084fa2 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.0.0 +1.1.0