Skip to content

Commit 7968aa2

Browse files
authored
✨ Added github_actions plugin (#60)
<!-- Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved. SPDX-License-Identifier: Apache-2.0 --> ### Description Added `github_actions` plugin ### Test Coverage <!-- Please put an `x` in the correct box e.g. `[x]` to indicate the testing coverage of this change. --> - [ ] This change is covered by existing or additional automated tests. - [ ] Manual testing has been performed (and evidence provided) as automated testing was not feasible. - [x] Additional tests are not required for this change (e.g. documentation update).
1 parent 2d0048f commit 7968aa2

File tree

12 files changed

+142
-30
lines changed

12 files changed

+142
-30
lines changed

.secrets.baseline

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
"filename": "continuous_delivery_scripts/plugins/python.py",
108108
"hashed_secret": "a5c8a5463c338b832f4afbe616ae77b4ecbfadc0",
109109
"is_verified": false,
110-
"line_number": 26
110+
"line_number": 27
111111
}
112112
],
113113
"continuous_delivery_scripts/utils/git_helpers.py": [
@@ -425,5 +425,5 @@
425425
}
426426
]
427427
},
428-
"generated_at": "2022-11-30T17:07:25Z"
428+
"generated_at": "2022-12-21T20:50:40Z"
429429
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Github Actions configuration plugin
2+
3+
This plugin is used for [GitHub Actions](https://github.com/features/actions) configuration projects when `PROGRAMMING_LANGUAGE` is set to `github_actions`.
4+
5+
This plugin is dedicated to managing GitHub Actions and workflows and is expected to run within this CI system.
6+
7+
## Prerequisites
8+
This plugin expects the [GitHub CLI](https://cli.github.com) to be installed and available from the path.
9+
10+
## Release
11+
The plugin carries out the same git actions as the [CI](./CI.MD) plugin but also performs extra GitHub actions such as release creation, etc.
12+
13+
## Documentation
14+
The plugin does not generate any documentation.

continuous_delivery_scripts/plugins/ci.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from continuous_delivery_scripts.spdx_report.spdx_project import SpdxProject
1111
from continuous_delivery_scripts.utils.configuration import configuration, ConfigurationVariable
12+
from continuous_delivery_scripts.utils.definitions import CommitType
1213
from continuous_delivery_scripts.utils.git_helpers import GitWrapper
1314
from continuous_delivery_scripts.utils.language_specifics_base import BaseLanguage, get_language_from_file_name
1415

@@ -18,10 +19,9 @@
1819
class CI(BaseLanguage):
1920
"""Specific actions for a CI project."""
2021

21-
def package_software(self, version: str) -> None:
22-
"""No operation."""
23-
super().package_software(version)
24-
# Nothing to do
22+
def package_software(self, mode: CommitType, version: str) -> None:
23+
"""Nothing to do."""
24+
pass
2525

2626
def generate_code_documentation(self, output_directory: Path, module_to_document: str) -> None:
2727
"""Generates the code documentation."""
@@ -37,9 +37,9 @@ def get_version_tag(self, version: str):
3737
cleansed_version = version.strip().lstrip("v")
3838
return f"v{cleansed_version}"
3939

40-
def release_package_to_repository(self, version: str) -> None:
40+
def release_package_to_repository(self, mode: CommitType, version: str) -> None:
4141
"""No operation."""
42-
super().release_package_to_repository(version)
42+
pass
4343

4444
def check_credentials(self) -> None:
4545
"""Checks any credentials."""

continuous_delivery_scripts/plugins/docker.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pathlib import Path
88
from typing import Optional
99
from continuous_delivery_scripts.utils.language_specifics_base import BaseLanguage, get_language_from_file_name
10+
from continuous_delivery_scripts.utils.definitions import CommitType
1011
from continuous_delivery_scripts.spdx_report.spdx_project import SpdxProject
1112

1213
logger = logging.getLogger(__name__)
@@ -19,13 +20,13 @@ def get_related_language(self) -> str:
1920
"""Gets the related language."""
2021
return get_language_from_file_name(__file__)
2122

22-
def package_software(self, version: str) -> None:
23+
def package_software(self, mode: CommitType, version: str) -> None:
2324
"""Todo build docker image."""
24-
super().package_software(version)
25+
super().package_software(mode, version)
2526

26-
def release_package_to_repository(self, version: str) -> None:
27+
def release_package_to_repository(self, mode: CommitType, version: str) -> None:
2728
"""Todo push image to repository e.g. ecr, artifactory."""
28-
super().release_package_to_repository(version)
29+
super().release_package_to_repository(mode, version)
2930

3031
def check_credentials(self) -> None:
3132
"""Checks any credentials."""
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#
2+
# Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
"""Plugin for CI projects."""
6+
import logging
7+
import os
8+
from pathlib import Path
9+
from subprocess import check_call
10+
from typing import List
11+
12+
from continuous_delivery_scripts.plugins.ci import CI
13+
from continuous_delivery_scripts.utils.configuration import configuration, ConfigurationVariable
14+
from continuous_delivery_scripts.utils.definitions import CommitType
15+
from continuous_delivery_scripts.utils.language_specifics_base import get_language_from_file_name
16+
17+
logger = logging.getLogger(__name__)
18+
ENVVAR_GITHUB_CLI_GIT_TOKEN = "GITHUB_TOKEN"
19+
20+
21+
def _generate_github_cli_release_command_list(
22+
changelog: Path, version: str, tag: str, is_latest: bool, is_prerelease: bool
23+
) -> List[str]:
24+
cmd = [
25+
"ght",
26+
"release",
27+
"--latest",
28+
"--notes-file",
29+
f"{str(changelog)}",
30+
]
31+
title = f":sparkles: Release {version}"
32+
if is_latest:
33+
cmd.append("--latest")
34+
if is_prerelease:
35+
cmd.append("--prerelease")
36+
title = f":news: Pre-release {version}"
37+
cmd.append("--title")
38+
cmd.append(title)
39+
cmd.append(tag)
40+
return cmd
41+
42+
43+
def _generate_github_cli_check_command_list() -> List[str]:
44+
return [
45+
"gh",
46+
"--version",
47+
]
48+
49+
50+
def _call_github_cli_check() -> None:
51+
"""Calls gh to verify its accessibility."""
52+
logger.info("Checking GitHub Actions is correctly installed.")
53+
env = os.environ
54+
env[ENVVAR_GITHUB_CLI_GIT_TOKEN] = configuration.get_value(ConfigurationVariable.GIT_TOKEN)
55+
check_call(_generate_github_cli_check_command_list(), env=env)
56+
57+
58+
class GitHubActions(CI):
59+
"""Specific actions for a GitHub Action project."""
60+
61+
def package_software(self, mode: CommitType, version: str) -> None:
62+
"""No operation."""
63+
super().package_software(mode, version)
64+
_call_github_cli_check()
65+
66+
def get_related_language(self) -> str:
67+
"""Gets the related language."""
68+
return get_language_from_file_name(__file__)
69+
70+
def release_package_to_repository(self, mode: CommitType, version: str) -> None:
71+
"""No operation."""
72+
super().release_package_to_repository(mode, version)
73+
is_latest = mode == CommitType.RELEASE
74+
is_prerelease = mode == CommitType.BETA
75+
self._call_github_cli_release(version, is_latest, is_prerelease)
76+
77+
def _call_github_cli_release(self, version: str, is_latest: bool, is_prerelease: bool) -> None:
78+
"""Calls github cli to create a release."""
79+
tag = self.get_version_tag(version)
80+
logger.info(f"Create a GitHub Release {version}")
81+
changelogPath = configuration.get_value(ConfigurationVariable.CHANGELOG_FILE_PATH)
82+
env = os.environ
83+
env[ENVVAR_GITHUB_CLI_GIT_TOKEN] = configuration.get_value(ConfigurationVariable.GIT_TOKEN)
84+
85+
check_call(
86+
_generate_github_cli_release_command_list(changelogPath, version, tag, is_latest, is_prerelease), env=env
87+
)

continuous_delivery_scripts/plugins/golang.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from continuous_delivery_scripts.utils.language_specifics_base import BaseLanguage, get_language_from_file_name
1212
from continuous_delivery_scripts.spdx_report.spdx_project import SpdxProject
1313
from continuous_delivery_scripts.utils.configuration import configuration, ConfigurationVariable
14+
from continuous_delivery_scripts.utils.definitions import CommitType
1415
from continuous_delivery_scripts.utils.git_helpers import LocalProjectRepository, GitWrapper
1516

1617
logger = logging.getLogger(__name__)
@@ -124,14 +125,14 @@ def get_version_tag(self, version: str):
124125
cleansed_version = version.strip().lstrip("v")
125126
return f"v{cleansed_version}"
126127

127-
def package_software(self, version: str) -> None:
128+
def package_software(self, mode: CommitType, version: str) -> None:
128129
"""No operation."""
129130
super().package_software(version)
130131
_call_goreleaser_check(version)
131132

132-
def release_package_to_repository(self, version: str) -> None:
133+
def release_package_to_repository(self, mode: CommitType, version: str) -> None:
133134
"""No operation."""
134-
super().release_package_to_repository(version)
135+
super().release_package_to_repository(mode, version)
135136
self._call_goreleaser_release(version)
136137

137138
def check_credentials(self) -> None:

continuous_delivery_scripts/plugins/noop.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pathlib import Path
88

99
from continuous_delivery_scripts.spdx_report.spdx_project import SpdxProject
10+
from continuous_delivery_scripts.utils.definitions import CommitType
1011
from continuous_delivery_scripts.utils.language_specifics_base import BaseLanguage, get_language_from_file_name
1112
from typing import Optional
1213

@@ -20,13 +21,13 @@ def get_related_language(self) -> str:
2021
"""Gets the related language."""
2122
return get_language_from_file_name(__file__)
2223

23-
def package_software(self, version: str) -> None:
24+
def package_software(self, mode: CommitType, version: str) -> None:
2425
"""No Op."""
25-
super().package_software(version)
26+
super().package_software(mode, version)
2627

27-
def release_package_to_repository(self, version: str) -> None:
28+
def release_package_to_repository(self, mode: CommitType, version: str) -> None:
2829
"""No Op."""
29-
super().release_package_to_repository(version)
30+
super().release_package_to_repository(mode, version)
3031

3132
def check_credentials(self) -> None:
3233
"""No Op."""

continuous_delivery_scripts/plugins/python.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from continuous_delivery_scripts.utils.language_specifics_base import BaseLanguage, get_language_from_file_name
1515
from continuous_delivery_scripts.spdx_report.spdx_project import SpdxProject
1616
from continuous_delivery_scripts.utils.configuration import configuration, ConfigurationVariable
17+
from continuous_delivery_scripts.utils.definitions import CommitType
1718
from continuous_delivery_scripts.utils.filesystem_helpers import TemporaryDirectory
1819
from continuous_delivery_scripts.utils.filesystem_helpers import cd
1920
from continuous_delivery_scripts.utils.logging import log_exception
@@ -134,14 +135,14 @@ def get_related_language(self) -> str:
134135
"""Gets related language."""
135136
return get_language_from_file_name(__file__)
136137

137-
def package_software(self, version: str) -> None:
138+
def package_software(self, mode: CommitType, version: str) -> None:
138139
"""Packages the software into a wheel."""
139-
super().package_software(version)
140+
super().package_software(mode, version)
140141
_create_wheel()
141142

142-
def release_package_to_repository(self, version: str) -> None:
143+
def release_package_to_repository(self, mode: CommitType, version: str) -> None:
143144
"""Releases to PyPI."""
144-
super().release_package_to_repository(version)
145+
super().release_package_to_repository(mode, version)
145146
_release_to_pypi()
146147

147148
def check_credentials(self) -> None:

continuous_delivery_scripts/tag_and_release.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def tag_and_release(mode: CommitType, current_branch: Optional[str] = None) -> N
5555
_clean_repository()
5656
if spdx_project and get_language_specifics().should_include_spdx_in_package():
5757
_generate_spdx_reports(spdx_project)
58-
get_language_specifics().package_software(version)
59-
get_language_specifics().release_package_to_repository(version)
58+
get_language_specifics().package_software(mode, version)
59+
get_language_specifics().release_package_to_repository(mode, version)
6060

6161

6262
def _get_documentation_config() -> Tuple[Path, str]:

continuous_delivery_scripts/utils/language_specifics_base.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from continuous_delivery_scripts.spdx_report.spdx_project import SpdxProject
1313
from continuous_delivery_scripts.utils.configuration import configuration, ConfigurationVariable
14+
from continuous_delivery_scripts.utils.definitions import CommitType
1415
from continuous_delivery_scripts.utils.git_helpers import GitWrapper
1516

1617
logger = logging.getLogger(__name__)
@@ -91,13 +92,18 @@ def generate_code_documentation(self, output_directory: Path, module_to_document
9192
pass
9293

9394
@abstractmethod
94-
def package_software(self, version: str) -> None:
95+
def package_software(self, mode: CommitType, version: str) -> None:
9596
"""Package the software so that it can get released."""
96-
logger.info(f"Generating a release package [{version}]")
97+
if mode == CommitType.RELEASE:
98+
logger.info(f"Generating a release package [{version}]")
99+
elif mode == CommitType.BETA:
100+
logger.info(f"Generating a pre-release package [{version}]")
101+
else:
102+
logger.info(f"Generating a development package [{version}]")
97103
pass
98104

99105
@abstractmethod
100-
def release_package_to_repository(self, version: str) -> None:
106+
def release_package_to_repository(self, mode: CommitType, version: str) -> None:
101107
"""Release the package to the official software repository."""
102108
logger.info(f"Uploading the package [{version}]")
103109
pass

0 commit comments

Comments
 (0)