-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsite-builder.yml
215 lines (178 loc) · 8.65 KB
/
site-builder.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
################################################################################
# Copyright (c) IBM Corporation 2020
#
# Description:
# This playbook will generate documentation for all collections in the
# registry.yml, perform validation, allow for a preview of generated doc
#
# Usage:
# ansible-playbook -i inventory site-builder.yml
################################################################################
---
- hosts: all
gather_facts: no
connection: local
# ##############################################################################
# # Parse 'registry.yml' for certified contributors (key:value)
# ##############################################################################
tasks:
- name: Parse the registry for collection entries
include_vars: registry.yml
- name: Display the registered collections and properites in `registry.yml`.
debug:
var: collections[item]
with_items: "{{collections}}"
############################################################################
# Evaluate the state of all collections currently in the repo and compare
# them to the registry.yml
#############################################################################
- name: Evaluate which collections are in directory `source/<collection>`
stat:
path: source/{{ item }}
register: git_submodule
with_items: "{{collections}}"
- name: Display the colletions in directory `source/<collection>`
debug:
msg: "Collection source/{{item.item}} exists."
with_items: "{{ git_submodule.results }}"
############################################################################
# Check if there are changes to .gitmodules that are not staged or stashed
# that will result in this playbook failing to properly teardown then init
# based on the registry.yml.
# Avoids this error:
# fatal: Please, stage your changes to .gitmodules or stash them to proceed
############################################################################
- name: Check status of `.gitmodules`.
shell: |
git status --untracked-files=no --porcelain .gitmodules
register: status_gitmodules
- name: Display status of `.gitmodules`.
debug: msg="{{status_gitmodules}}"
- name: Evaluate if `.gitmodules` has unstaged changes.
set_fact:
status_gitmodule_M: "{{ status_gitmodules.stdout | regex_search('^\\s*M ')}}"
- name: Display if `.gitmodules` has unstaged changes
debug:
msg: "Unstaged changes have been found in .gitsubmodules."
when: status_gitmodule_M
# If you modify a file, then:
# (A) use git add to copy it to the index / staging-area
# (B) modify it again, now all three versions of that file differ.
# This is will generate the MM status.
- name: Evaluate if `.gitmodules` has staged and unstaged changes.
set_fact:
status_gitmodule_MM: "{{ status_gitmodules.stdout | regex_search('^\\s*MM ')}}"
- name: Display if `.gitmodules` has staged and unstaged changes.
debug:
msg: "Staged and unstaged changes have been found in .gitsubmodules."
when: status_gitmodule_MM
- name: Reset .gitmodules if there are staged and unstaged changes.
shell: |
git reset HEAD .gitmodules
when: status_gitmodule_MM
- name: Stagging .gitmodules
shell: |
git add .gitmodules
register: add_gitmodules
when: status_gitmodule_M or status_gitmodule_MM
- name: Display result from staging .gitmodules.
debug: msg="{{add_gitmodules}}"
when: status_gitmodule_M or status_gitmodule_MM
- name: Display summary of changes.
debug: msg="Changes have been detected for '.gitmodules', changes have been
staged, you may unstage them with command 'git reset HEAD .gitmodules'"
when: status_gitmodule_M or status_gitmodule_MM
# ############################################################################
# Complete teardown and setup of all submodules to avoid conflicts when new
# private branches are added to the registry.yml and not properly udated in
# the .gitmodules config; just makes for a cleaner run and less troubleshooting
# for those who don't properly maintain their clone repository
#
# NOTE: This only manages the submodules in the `registry.yml` not any
# submodules excluded from the registry.yml
# ############################################################################
# NOTE: Performing this as a single task introduces failures that can not be ignored.
# Thus it has been reduced to individual tasks.
# - name: Teardown all submodules then init them according to `registry.yml`.
# shell: |
# git rm -f --cached source/{{ item }}
# rm -rf source/{{ item }}
# rm -rf .git/modules/source/{{ item }}
# git config -f .gitmodules --remove-section submodule.source/{{ item }}
# git submodule add {{ collections[item].git}} source/{{ item }}
# git submodule init
# with_items: "{{collections}}"
# register: git_add_submodules
# - name: Display the result from the teardown and init for all submodules registerd in `registry.yml`.
# debug: msg="{{ git_add_submodules }}"
# when: git_add_submodules
- name: 1 - Remove cached submodules according to `registry.yml`.
shell: |
git rm -f --cached source/{{ item }}
with_items: "{{collections}}"
register: git_add_submodules_1
ignore_errors: yes
- name: 1 - Display Remove cached submodules according to `registry.yml`.
debug: msg="{{ git_add_submodules_1 }}"
when: git_add_submodules_1
- name: 2 - Remove local files according to `registry.yml`.
shell: |
rm -rf source/{{ item }}
with_items: "{{collections}}"
register: git_add_submodules_2
- name: 2 - Display remove local files according to `registry.yml`.
debug: msg="{{ git_add_submodules_2 }}"
when: git_add_submodules_2
- name: 3 - Remove all git managed submodule content according to `registry.yml`.
shell: |
rm -rf .git/modules/source/{{ item }}
with_items: "{{collections}}"
register: git_add_submodules_3
- name: 3 - Display remove all git managed submodule content according to `registry.yml`.
debug: msg="{{ git_add_submodules_3 }}"
when: git_add_submodules_3
- name: 4 - Remove .gitmodules references for all submodules according to `registry.yml`.
shell: |
git config -f .gitmodules --remove-section submodule.source/{{ item }}
with_items: "{{collections}}"
register: git_add_submodules_4
ignore_errors: yes
- name: 4 - Display remove .gitmodules references for all submodules according to `registry.yml`.
debug: msg="{{ git_add_submodules_4 }}"
when: git_add_submodules_4
- name: 5 - Add all submodules to .gitmodules according to `registry.yml`.
shell: |
git submodule add {{ collections[item].git}} source/{{ item }}
with_items: "{{collections}}"
register: git_add_submodules_5
- name: 5 - Display add all submodules to .gitmodules according to `registry.yml`.
debug: msg="{{ git_add_submodules_5 }}"
when: git_add_submodules_5
- name: 6 - Init all submodules according to `registry.yml`.
shell: |
git submodule init
with_items: "{{collections}}"
register: git_add_submodules_6
- name: 6 - Init all submodules according to `registry.yml`.
debug: msg="{{ git_add_submodules_6 }}"
when: git_add_submodules_6
############################################################################
# After teardown and init, traverse each submodule and checkout the latest
# branch indentified in registry.yml
############################################################################
- name: Update each of the submodule contents under `source/<submodule>`.
shell: |
cd source/{{ item }}
git fetch --all
git reset --hard origin/{{ collections[item].origin }}
git checkout {{ collections[item].latest }}
git pull origin {{ collections[item].latest }}
with_items: "{{collections}}"
register: git_checkout_latest
- name: Display the results after updating the submodules under `source/<submodule>`.
debug: msg="{{ git_checkout_latest }}"
############################################################################
# Generate and view HTML
############################################################################
- name: Generate HTML and display the results locally in the users browser
raw: make clean; make html; make view-html;