Skip to content

Commit a6d5ace

Browse files
committed
Added CI to create PRs to bump repos on main
1 parent f032ed9 commit a6d5ace

File tree

5 files changed

+160
-0
lines changed

5 files changed

+160
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Check for new Release Train snapshots
2+
on:
3+
workflow_dispatch:
4+
schedule:
5+
- cron: '0 7 * * *' # Run at 7am on default branch
6+
7+
jobs:
8+
upstream_check:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
13+
- name: Setup environment
14+
run: |
15+
. venv/bin/activate
16+
. environments/.stackhpc/activate
17+
18+
- name: Check for updated Ark timestamps and replace in defaults.yml
19+
run: ansible-playbook ansible/ci/update_timestamps.yml
20+
21+
- name: Create Pull Request
22+
uses: peter-evans/create-pull-request@v7
23+
with:
24+
add-paths: environments/common/inventory/group_vars/all/defaults.yml
25+
commit-message: "[automated] bumped repo timestamps to latest"
26+
branch: auto/bump-timestamps
27+
title: "[Automation] Bumped repo timestamps to latest"
28+
body: Automated changes by .github/workflows/update-timestamps.yml
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/python
2+
3+
# Copyright: (c) 2018, Terry Jones <terry.jones@example.org>
4+
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5+
from __future__ import (absolute_import, division, print_function)
6+
__metaclass__ = type
7+
8+
DOCUMENTATION = r'''
9+
---
10+
module: latest_timestamps
11+
12+
short_description: Gets the latest set of snapshots from Pulp and overwrites
13+
14+
version_added: "1.0.0"
15+
16+
description: Gets the latest set of snapshots from given source URLs and returns dictionary in to replace 'appliances_repo_timestamps' with
17+
18+
author:
19+
- William Tripp
20+
'''
21+
22+
EXAMPLES = r'''
23+
# Pass in a message
24+
- name: Get latest timestamps
25+
latest_timestamps:
26+
current_timestamps_dict: "{{ appliances_repo_timestamps }}"
27+
sources_dict: "{{ appliances_repo_timestamp_sources }}"
28+
register: result
29+
30+
'''
31+
32+
RETURN = r'''
33+
# These are examples of possible return values, and in general should use other names for return values.
34+
latest_dict:
35+
description: Dictionary with updated timestamps
36+
type: dict
37+
returned: always
38+
changed_timestamps:
39+
description: List of repos that've been updated
40+
type: str[]
41+
returned: always
42+
'''
43+
44+
from ansible.module_utils.basic import AnsibleModule
45+
import requests
46+
from bs4 import BeautifulSoup
47+
48+
def run_module():
49+
module_args = dict(
50+
current_timestamps_dict=dict(type='dict', required=True),
51+
sources_dict=dict(type='dict', required=True)
52+
)
53+
54+
result = dict(
55+
changed=False,
56+
original_message='',
57+
message=''
58+
)
59+
60+
module = AnsibleModule(
61+
argument_spec=module_args,
62+
supports_check_mode=True
63+
)
64+
65+
latest_timestamps = {}
66+
changed_timestamps = []
67+
for repo in module.params['sources_dict']:
68+
latest_timestamps[repo] = module.params['sources_dict'][repo]
69+
for version in module.params['sources_dict'][repo]:
70+
html_txt = requests.get(url=module.params['sources_dict'][repo][version]).text
71+
timestamp_link_list = BeautifulSoup(html_txt,features="html.parser").body.find('pre').find_all()
72+
timestamp_link_list = map(lambda x: x.string,timestamp_link_list) # xml tags
73+
latest_timestamps[repo][version] = list(timestamp_link_list)[-1][:-1] # last timestamp in list with trailing / removed
74+
if module.params['sources_dict'][repo][version] != module.params['current_timestamps_dict'][repo][version]:
75+
changed_timestamps.append(repo+' '+version)
76+
77+
result['latest_dict'] = latest_timestamps
78+
result['changed_timestamps'] = changed_timestamps
79+
80+
module.exit_json(**result)
81+
82+
83+
def main():
84+
run_module()
85+
86+
87+
if __name__ == '__main__':
88+
main()

ansible/ci/update_timestamps.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
- hosts: localhost
2+
tasks:
3+
- name: Check sources are defined for all repos
4+
ansible.builtin.assert:
5+
that: appliances_repo_timestamps[item].keys() == appliances_repo_timestamp_sources[item].keys()
6+
fail_msg: "'appliances_repo_timestamps.{{ item }}' is missing a source definition in 'appliances_repo_timestamp_sources'"
7+
loop: "{{ appliances_repo_timestamps.keys() }}"
8+
9+
- name: Get latest timestamps from sources
10+
latest_timestamps:
11+
sources_dict: "{{ appliances_repo_timestamp_sources }}"
12+
current_timestamps_dict: "{{ appliances_repo_timestamps }}"
13+
register: _result
14+
15+
- name: Print updated timestamps
16+
ansible.builtin.debug:
17+
var: _result.changed_timestamps
18+
19+
- name: Overwrite repo timestamps with latest
20+
ansible.builtin.blockinfile:
21+
path: "{{ playbook_dir }}/../../environments/common/inventory/group_vars/all/defaults.yml"
22+
marker: "# {mark} Marker for ansible/ci/update_timestamps.yml (GH workflow managed)"
23+
block: |
24+
{{ yaml_template | to_nice_yaml(indent=2) }}
25+
vars:
26+
yaml_template:
27+
appliances_repo_timestamps: "{{ _result.latest_dict }}"
28+
when: (_result.changed_timestamps | count) > 0

environments/common/inventory/group_vars/all/defaults.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ appliances_local_users: "{{ appliances_local_users_default + appliances_local_us
8282

8383
###########################################################################################
8484

85+
# BEGIN Marker for ansible/ci/update_timestamps.yml (GH workflow managed)
8586
appliances_repo_timestamps:
8687
baseos:
8788
'9.4': 20240816T002610
@@ -93,3 +94,17 @@ appliances_repo_timestamps:
9394
'9.4': 20240816T002610
9495
epel:
9596
'9': 20240902T080424
97+
# END Marker for ansible/ci/update_timestamps.yml (GH workflow managed)
98+
99+
# For CI
100+
appliances_repo_timestamp_sources:
101+
baseos:
102+
'9.4': https://ark.stackhpc.com/pulp/content/rocky/9.4/BaseOS/x86_64/os/
103+
appstream:
104+
'9.4': https://ark.stackhpc.com/pulp/content/rocky/9.4/AppStream/x86_64/os/
105+
crb:
106+
'9.4': https://ark.stackhpc.com/pulp/content/rocky/9.4/CRB/x86_64/os/
107+
extras:
108+
'9.4': https://ark.stackhpc.com/pulp/content/rocky/9.4/extras/x86_64/os/
109+
epel:
110+
'9': https://ark.stackhpc.com/pulp/content/epel/9/Everything/x86_64/

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ selinux # this is a shim to avoid having to use --system-site-packages, you stil
1010
netaddr
1111
matplotlib
1212
pulp-cli==0.29.2
13+
beautifulsoup4==4.12.3

0 commit comments

Comments
 (0)