mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Allow creation of github release tags (#25338)
* Allow creation of github release tags * Reword description * Prefer to use required_if
This commit is contained in:
parent
6bc15d11b9
commit
6ba49f42c2
1 changed files with 77 additions and 3 deletions
|
@ -53,7 +53,42 @@ options:
|
||||||
required: true
|
required: true
|
||||||
description:
|
description:
|
||||||
- Action to perform
|
- Action to perform
|
||||||
choices: [ 'latest_release' ]
|
choices: [ 'latest_release', 'create_release' ]
|
||||||
|
tag:
|
||||||
|
required: false
|
||||||
|
description:
|
||||||
|
- Tag name when creating a release. Required when using action is set to C(create_release).
|
||||||
|
version_added: 2.4
|
||||||
|
target:
|
||||||
|
required: false
|
||||||
|
description:
|
||||||
|
- Target of release when creating a release
|
||||||
|
version_added: 2.4
|
||||||
|
name:
|
||||||
|
required: false
|
||||||
|
description:
|
||||||
|
- Name of release when creating a release
|
||||||
|
version_added: 2.4
|
||||||
|
body:
|
||||||
|
required: false
|
||||||
|
description:
|
||||||
|
- Description of the release when creating a release
|
||||||
|
version_added: 2.4
|
||||||
|
draft:
|
||||||
|
required: false
|
||||||
|
description:
|
||||||
|
- Sets if the release is a draft or not. (boolean)
|
||||||
|
default: false
|
||||||
|
version_added: 2.4
|
||||||
|
choices: ['True', 'False']
|
||||||
|
prerelease:
|
||||||
|
required: false
|
||||||
|
description:
|
||||||
|
- Sets if the release is a prerelease or not. (boolean)
|
||||||
|
default: false
|
||||||
|
version_added: 2.4
|
||||||
|
choices: ['True', 'False']
|
||||||
|
|
||||||
|
|
||||||
author:
|
author:
|
||||||
- "Adrian Moisey (@adrianmoisey)"
|
- "Adrian Moisey (@adrianmoisey)"
|
||||||
|
@ -62,7 +97,7 @@ requirements:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
- name: Get latest release of test/test
|
- name: Get latest release of testuseer/testrepo
|
||||||
github_release:
|
github_release:
|
||||||
token: tokenabc1234567890
|
token: tokenabc1234567890
|
||||||
user: testuser
|
user: testuser
|
||||||
|
@ -75,6 +110,18 @@ EXAMPLES = '''
|
||||||
password: secret123
|
password: secret123
|
||||||
repo: testrepo
|
repo: testrepo
|
||||||
action: latest_release
|
action: latest_release
|
||||||
|
|
||||||
|
- name: Create a new release
|
||||||
|
github:
|
||||||
|
token: tokenabc1234567890
|
||||||
|
user: testuser
|
||||||
|
repo: testrepo
|
||||||
|
action: create_release
|
||||||
|
tag: test
|
||||||
|
target: master
|
||||||
|
name: My Release
|
||||||
|
body: Some description
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
|
@ -101,11 +148,19 @@ def main():
|
||||||
user=dict(required=True),
|
user=dict(required=True),
|
||||||
password=dict(no_log=True),
|
password=dict(no_log=True),
|
||||||
token=dict(no_log=True),
|
token=dict(no_log=True),
|
||||||
action=dict(required=True, choices=['latest_release']),
|
action=dict(
|
||||||
|
required=True, choices=['latest_release', 'create_release']),
|
||||||
|
tag=dict(type='str'),
|
||||||
|
target=dict(type='str'),
|
||||||
|
name=dict(type='str'),
|
||||||
|
body=dict(type='str'),
|
||||||
|
draft=dict(type='bool', default=False),
|
||||||
|
prerelease=dict(type='bool', default=False),
|
||||||
),
|
),
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
required_one_of=(('password', 'token'),),
|
required_one_of=(('password', 'token'),),
|
||||||
mutually_exclusive=(('password', 'token'),),
|
mutually_exclusive=(('password', 'token'),),
|
||||||
|
required_if=[('action', 'create_release', ['tag'])],
|
||||||
)
|
)
|
||||||
|
|
||||||
if not HAS_GITHUB_API:
|
if not HAS_GITHUB_API:
|
||||||
|
@ -117,6 +172,12 @@ def main():
|
||||||
password = module.params['password']
|
password = module.params['password']
|
||||||
login_token = module.params['token']
|
login_token = module.params['token']
|
||||||
action = module.params['action']
|
action = module.params['action']
|
||||||
|
tag = module.params.get('tag')
|
||||||
|
target = module.params.get('target')
|
||||||
|
name = module.params.get('name')
|
||||||
|
body = module.params.get('body')
|
||||||
|
draft = module.params.get('draft')
|
||||||
|
prerelease = module.params.get('prerelease')
|
||||||
|
|
||||||
# login to github
|
# login to github
|
||||||
try:
|
try:
|
||||||
|
@ -145,6 +206,19 @@ def main():
|
||||||
else:
|
else:
|
||||||
module.exit_json(tag=None)
|
module.exit_json(tag=None)
|
||||||
|
|
||||||
|
if action == 'create_release':
|
||||||
|
release_exists = repository.release_from_tag(tag)
|
||||||
|
if release_exists:
|
||||||
|
module.exit_json(
|
||||||
|
skipped=True, msg="Release for tag %s already exists." % tag)
|
||||||
|
|
||||||
|
release = repository.create_release(
|
||||||
|
tag, target, name, body, draft, prerelease)
|
||||||
|
if release:
|
||||||
|
module.exit_json(tag=release.tag_name)
|
||||||
|
else:
|
||||||
|
module.exit_json(tag=None)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in a new issue