Skip to content

Commit bfa2f51

Browse files
committed
Merge branch 'prod' into lb
2 parents 7255687 + 246ee4e commit bfa2f51

File tree

14 files changed

+453
-136
lines changed

14 files changed

+453
-136
lines changed

CHANGELOG.md

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,64 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7-
## [Unreleased]
7+
## [0.5.7] - 2023-12-07
8+
9+
### Fixed
10+
11+
- Always create submit token.
12+
13+
## [0.5.6] - 2023-12-07
14+
15+
### Fixed
16+
17+
- Explain access denied error message in submit job.
18+
19+
## [0.5.5] - 2023-10-06
20+
21+
### Changed
22+
23+
- Remove distribute NAMESPACE format check.
24+
25+
## [0.5.4] - 2023-09-21
26+
27+
### Fixed
28+
29+
- Submit job commits .results by mistake.
30+
31+
## [0.5.3] - 2023-09-21
32+
33+
### Fixed
34+
35+
- Submit job is failing.
36+
37+
## [0.5.2] - 2023-08-06
38+
39+
### Fixed
40+
41+
- Academy execute job has wrong conditions.
42+
43+
## [0.5.1] - 2023-05-10
44+
45+
### Fixed
46+
47+
- Switching academy version in gitlab-ci include causes ci error.
48+
- Distribute not working due to invalid variable.
49+
50+
### Added
51+
52+
- Add --force-merge param to distribute.
53+
54+
## [0.5.0] - 2023-05-02
55+
56+
_Stable release based on [0.5.0-rc.1]._
57+
58+
## [0.5.0-rc.1] - 2023-05-02
59+
60+
### Added
61+
62+
- Extened badge_generate function adding file, link and title params
63+
64+
## [0.4.0] - 2023-03-05
865
### Added
966
- Change default prefix to project_name+ instead of project_name-
1067

@@ -22,7 +79,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2279
- Set name of distributed project as `original_project_name user_name`
2380

2481

25-
[Unreleased]: https://github.com/internetguru/academy/compare/master...dev
82+
[0.5.7]: https://https://github.com/internetguru/academy/compare/v0.5.6...v0.5.7
83+
[0.5.6]: https://https://github.com/internetguru/academy/compare/v0.5.5...v0.5.6
84+
[0.5.5]: https://https://github.com/internetguru/academy/compare/v0.5.4...v0.5.5
85+
[0.5.4]: https://https://github.com/internetguru/academy/compare/v0.5.3...v0.5.4
86+
[0.5.3]: https://https://github.com/internetguru/academy/compare/v0.5.2...v0.5.3
87+
[0.5.2]: https://https://github.com/internetguru/academy/compare/v0.5.1...v0.5.2
88+
[0.5.1]: https://https://github.com/internetguru/academy/compare/v0.5.0...v0.5.1
89+
[0.5.0]: https://https://github.com/internetguru/academy/compare/v0.4.0...v0.5.0
90+
[0.5.0-rc.1]: https://github.com/internetguru/academy/releases/tag/v0.4.0
91+
[0.4.0]: https://github.com/internetguru/academy/compare/v0.3.0...v0.4.0
2692
[0.3.0]: https://github.com/internetguru/academy/compare/v0.2.0...v0.3.0
2793
[0.2.0]: https://github.com/internetguru/academy/compare/v0.1.0...v0.2.0
2894
[0.1.0]: https://github.com/internetguru/academy/compare/v0.0.0...v0.1.0

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ Note: To execute individual commands, [trigger their pipeline](https://docs.gitl
9696

9797
## GitLab CI Variables
9898

99+
- `ACADEMY_DASHBOARD: "URL"`
100+
- Dashboard URL, e.g. https://academy.internetguru.io
99101
- `ACADEMY_DEADLINE: "DATE"`
100102
- See `--deadline` option in `academy collect` documentation.
101103
- `ACADEMY_EDITABLE: "PATTERN"`

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.0
1+
0.5.7

academy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ customize_academy() {
2323
local CUSTOM_ACADEMY='.academy'
2424
[[ -d "${CUSTOM_ACADEMY}" ]] \
2525
|| return
26-
cp "${CUSTOM_ACADEMY}"/* "${DIR}"
26+
cp -r "${CUSTOM_ACADEMY}"/* "${DIR}"
2727
}
2828

2929
# shellcheck disable=SC2155

badges

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,41 @@ url_encode() {
4141

4242
# generate badge
4343
badge_generate() {
44-
local badge_name="${1}"
45-
local ci_job="${CI_JOB_NAME:-local}"
46-
local badge_file="${badge_name// /-}"
47-
badge_file="${RESULTS:-${WORKING_DIR}/.results}/badge-${ci_job}-${badge_file,,}.svg"
48-
local badge_label
49-
badge_label="$( url_encode "${badge_name}" )"
50-
local badge_value
51-
badge_value="$( url_encode "${2}" )"
52-
local badge_color="${3}"
53-
[[ -z "${badge_color}" ]] \
54-
&& case "${2}" in
55-
n/a) badge_color="${DEFAULT_COLOR}";;
56-
*/*) badge_color="$( fraction_to_color "${2}" )";;
57-
*%) badge_color="$( percent_to_color "${2%\%}" )";;
58-
*) badge_color="${DEFAULT_COLOR}"
44+
# required
45+
local label="${1:-}"
46+
local value="${2:-}"
47+
[[ -z "${label}" || -z "${value}" ]] \
48+
&& echo 'Missing badge label or value' >&2 \
49+
&& return 2
50+
# optional
51+
local color="${3:-}"
52+
local file_name="${4:-}"
53+
local link="${5:-}"
54+
local title="${6:-}"
55+
# auto color
56+
[[ -z "${color}" ]] \
57+
&& case "${value}" in
58+
n/a) color="${DEFAULT_COLOR}" ;;
59+
*/*) color="$(fraction_to_color "${value}")" ;;
60+
*%) color="$(percent_to_color "${value%\%}")" ;;
61+
*) color="${DEFAULT_COLOR}"
5962
esac
60-
curl -so "${badge_file}" "${SHIELDS}?label=${badge_label}&message=${badge_value}&color=${badge_color}"
63+
# default badge name is "badge-[ci job name]-[normalized label]"
64+
# normalized label: spaces to dashes, to lowercase
65+
[[ -z "${file_name}" ]] \
66+
&& file_name="${label// /-}" \
67+
&& file_name="badge-${CI_JOB_NAME:-local}-${file_name,,}"
68+
# generate shileds.io badge
69+
WORKING_DIR="${WORKING_DIR:-.}"
70+
local dest="${RESULTS:-${WORKING_DIR}/.results}/${file_name}.svg"
71+
curl -so "${dest}" "${SHIELDS}?label=$(url_encode "${label}")&message=$(url_encode "${value}")&color=${color}"
72+
# always add link element with or without href
73+
# always cause of title not working only in svg, it needs to be in some element like <a>
74+
[[ -n "${link}" ]] \
75+
&& link="href=\"${link}\""
76+
sed -Ei "s~(<svg[^>]+>)(.*)(</svg>)~\1<a ${link}>\2</a>\3~" "${dest}"
77+
# update title
78+
[[ -n "${title}" ]] \
79+
&& sed -Ei "s~<title>.*</title>~<title>${title}</title>~" "${dest}"
80+
return 0
6181
}

commons

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ exception() {
5252
exit "${code}"
5353
}
5454
warning() {
55-
declare -r message="${1:-Unknown exception}"
55+
declare -r message="${1:-Unknown warning}"
5656
declare -ri code=${2:-1}
5757
(( code == 1 )) \
5858
&& printf -- '%s in %s() [ #%d ]\n' "${message}" "${FUNCNAME[1]}" "${code}" >&2 \

distribute

Lines changed: 100 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ init_cache() {
1010
git_clone "$(get_remote_url "${user_project_ns}")" "${user_cache_folder}"
1111
}
1212
sync_cache() {
13-
rsync -a --delete --exclude .git/ "${WORKING_DIR}/" "${user_cache_folder}" \
13+
rsync -a --delete --exclude .git/ ${3:-} "${1:-${WORKING_DIR}}/" "${2:-${user_cache_folder}}" \
1414
|| exception "Unable to rsync files"
15-
[[ "${UPDATE_LINKS}" == 'true' ]] \
16-
&& update_links
1715
}
1816
get_cache() {
1917
[[ ! -d "${user_cache_folder}" ]] \
@@ -26,12 +24,22 @@ get_cache() {
2624
[[ "${actual_remote_ns}" != "${user_project_ns}" ]] \
2725
&& exception 'Invalid user project remote origin url'
2826
git_pull "${user_cache_folder}" 'origin' "${SOURCE_BRANCH}:${SOURCE_BRANCH}"
27+
git_pull "${user_cache_folder}" 'origin' "${SUBMIT_BRANCH}:${SUBMIT_BRANCH}"
2928
git_pull "${user_cache_folder}" 'origin' "${user_default_branch}:${user_default_branch}"
3029
}
30+
# TODO
3131
update_links() {
32+
local user_cache_folder="${1:-${user_cache_folder}}"
33+
local PROJECT_LINK="${2:-${PROJECT_LINK}}"
34+
local user_project_ns="${3:-${user_project_ns}}"
35+
local PROJECT_BRANCH="${4:-${PROJECT_BRANCH}}"
36+
local user_default_branch="${5:-${user_default_branch}}"
37+
[[ "${UPDATE_LINKS}" != 'true' ]] \
38+
&& return
3239
declare -r user_readme_path="${user_cache_folder}/${README_FILE}"
3340
sed -i "s~${PROJECT_LINK}~${user_project_ns}~g" "${user_readme_path}"
3441
sed -i "s~/${PROJECT_BRANCH}/\(pipeline\|raw\|file\)~/${user_default_branch}/\1~g" "${user_readme_path}"
42+
sed -i "s~/\(pipeline\|raw\|file\)/${PROJECT_BRANCH}~/\1/${user_default_branch}~g" "${user_readme_path}"
3543
sed -i "s~ref=${PROJECT_BRANCH}~ref=${user_default_branch}~g" "${user_readme_path}"
3644
sed -i "s~\(https://[^/]*\)/${PROJECT_LINK#*/}~\1/${user_project_ns#*/}~g" "${user_readme_path}"
3745
}
@@ -48,7 +56,7 @@ init_user_repo() {
4856
|| exit 1
4957
project_id="$(create_user_project)" \
5058
|| exit 1
51-
add_developer
59+
add_member
5260
copy_issues
5361
init_cache
5462
git_commit "${user_cache_folder}" '--allow-empty' '-m "Initial commit"'
@@ -57,20 +65,27 @@ init_user_repo() {
5765
user_default_branch="$(get_default_branch)" \
5866
|| exit 1
5967
sync_cache
68+
update_links
6069
git_add_all "${user_cache_folder}"
6170
git_commit "${user_cache_folder}" '--allow-empty' '-m "Create assignment"'
6271
git_push "${user_cache_folder}" '--all'
6372
git_checkout "${user_cache_folder}" "-B${SOURCE_BRANCH}"
73+
git_checkout "${user_cache_folder}" "-B${SUBMIT_BRANCH}"
6474
git_push "${user_cache_folder}" '--all'
6575
remove_protected_branch
6676
set_protected_branch "${user_default_branch}" "${DEV_ACCESS_LEVEL}"
6777
set_protected_branch "${SOURCE_BRANCH}" "${MAINTAINER_ACCESS_LEVEL}"
78+
set_protected_branch "${SUBMIT_BRANCH}" "${MAINTAINER_ACCESS_LEVEL}"
6879
set_public_pages "${project_id}" >/dev/null
80+
create_project_submit_token
6981
}
7082
status_empty () {
7183
get_cache
84+
validate \
85+
|| return 1
7286
git_checkout "${user_cache_folder}" "${SOURCE_BRANCH}"
7387
sync_cache
88+
update_links
7489
git_status_empty "${user_cache_folder}"
7590
}
7691
update_user_repo() {
@@ -140,6 +155,57 @@ read_project_info() {
140155
&& issues_src="${ISSUES}" issues_count_src="${ISSUES_COUNT}"
141156
msg_end
142157
}
158+
validate_ci() {
159+
local branch="${1}"
160+
cmp -s "${WORKING_DIR}/.gitlab-ci.yml" <(git_show "origin/${branch}:.gitlab-ci.yml" "${user_cache_folder}") \
161+
|| echo "[WARNING] CI validation failed on ${branch}." >&2
162+
}
163+
validate() {
164+
# conform branches
165+
! git_remote_branch_exists "${SOURCE_BRANCH}" "${user_cache_folder}" \
166+
&& git_checkout "${user_cache_folder}" "-B${SOURCE_BRANCH}" \
167+
&& git_push "${user_cache_folder}" origin "${SOURCE_BRANCH}"
168+
! git_remote_branch_exists "${SUBMIT_BRANCH}" "${user_cache_folder}" \
169+
&& git_checkout "${user_cache_folder}" "-B${SUBMIT_BRANCH}" \
170+
&& git_push "${user_cache_folder}" origin "${SUBMIT_BRANCH}"
171+
# check ci hack
172+
validate_ci "${user_default_branch}"
173+
validate_ci "${SOURCE_BRANCH}"
174+
validate_ci "${SUBMIT_BRANCH}"
175+
}
176+
update_default_branch() {
177+
[[ -z "${DEFAULT_BRANCH_NAMESPACE}" ]] \
178+
&& return
179+
declare dest_default_branch
180+
declare dest_project_ns
181+
dest_default_branch="$(get_default_branch)"
182+
dest_project_ns="${user_project_ns}"
183+
declare dest_cache_folder
184+
declare user_cache_folder
185+
declare user_project_name
186+
declare user_project_ns
187+
declare user_default_branch
188+
dest_cache_folder="${1}"
189+
user_project_name="${PREFIX}${user_name}"
190+
user_project_ns="${DEFAULT_BRANCH_NAMESPACE}/${user_project_name}"
191+
user_cache_folder="$(get_cache_folder)"
192+
user_default_branch="$(get_default_branch)" \
193+
|| return 1
194+
get_cache
195+
git_checkout "${user_cache_folder}" "-B${user_default_branch}"
196+
git_checkout "${dest_cache_folder}" "-B${dest_default_branch}"
197+
sync_cache "${user_cache_folder}" "${dest_cache_folder}" --exclude=.gitlab-ci.yml
198+
# user_cache_folder ~ dest
199+
# PROJECT_LINK ~ src
200+
# user_project_ns ~ dest
201+
# PROJECT_BRANCH ~ src
202+
# user_default_branch ~ dest
203+
update_links "${dest_cache_folder}" "$(get_remote_namespace "${user_cache_folder}")" \
204+
"${dest_project_ns}" "${user_default_branch}" "${dest_default_branch}"
205+
git_add_all "${dest_cache_folder}"
206+
git_commit "${dest_cache_folder}" '--allow-empty' '-m "Update from user repo"'
207+
git_push "${dest_cache_folder}" '--all'
208+
}
143209
process_users() {
144210
declare user_name
145211
declare user_project_name
@@ -148,6 +214,7 @@ process_users() {
148214
declare user_default_branch
149215
declare -i valid=0
150216
declare -i invalid=0
217+
declare status_empty_code
151218
[[ -z "${CACHE_FOLDER}" ]] \
152219
&& CACHE_FOLDER="$(mktemp -d)"
153220
# shellcheck disable=SC2013
@@ -164,13 +231,24 @@ process_users() {
164231
&& msg_end SKIPPED \
165232
&& continue
166233
user_cache_folder="$(get_cache_folder)"
167-
! project_exists \
168-
&& init_user_repo \
169-
&& msg_end CREATED \
170-
&& continue
234+
if ! project_exists; then
235+
init_user_repo \
236+
&& update_default_branch "${user_cache_folder}" \
237+
&& msg_end CREATED
238+
continue
239+
fi
171240
user_default_branch="$(get_default_branch)" \
172241
|| exit 1
173-
status_empty \
242+
status_empty
243+
status_empty_code=$?
244+
update_default_branch "${user_cache_folder}" \
245+
|| continue
246+
project_id="$(get_project_id "${user_project_ns}")" \
247+
|| continue
248+
create_project_submit_token
249+
user_id="$(get_user_id)"
250+
add_member
251+
[[ "$status_empty_code" == 0 ]] \
174252
&& msg_end PASSED \
175253
&& continue
176254
update_user_repo \
@@ -197,6 +275,7 @@ distribute() {
197275
# global constants
198276
declare -r README_FILE='README.md'
199277
declare -r SOURCE_BRANCH='source'
278+
declare -r SUBMIT_BRANCH='submit'
200279
declare -r ALWAYS='always'
201280
declare -r NEVER='never'
202281
declare -r AUTO='auto'
@@ -214,6 +293,8 @@ declare PREFIX=''
214293
declare GROUP_ID=''
215294
declare PROJECT_LINK=''
216295
declare PROJECT_ID=''
296+
declare -i MEMBER_ROLE=$DEV_ACCESS_LEVEL
297+
declare DEFAULT_BRANCH_NAMESPACE=''
217298
# shellcheck disable=SC2034
218299
declare PROJECT_NAME=''
219300
declare PROJECT_BRANCH=''
@@ -227,8 +308,8 @@ declare FORCE_MERGE=0
227308

228309
# get options
229310
declare OPT
230-
OPT="$(getopt --name "${0}" --options 'a:hi:lno:p:s:m' \
231-
--longoptions 'assign:,help,process-issues:,update-links,dry-run,output-dir:,prefix:,namespace:,force-merge' \
311+
OPT="$(getopt --name "${0}" --options 'a:d:hi:lno:p:s:r:m' \
312+
--longoptions 'assign:,help,process-issues:,update-links,default-branch-namespace:,dry-run,output-dir:,prefix:,member-role:,namespace:,force-merge' \
232313
-- "$@")" \
233314
&& eval set -- "${OPT}" \
234315
|| exit 1
@@ -242,6 +323,10 @@ while (( $# > 0 )); do
242323
|| exception 'Invalid option ASSIGN value'
243324
shift 2
244325
;;
326+
-d|--default-branch-namespace)
327+
DEFAULT_BRANCH_NAMESPACE="${2}"
328+
shift 2
329+
;;
245330
-h|--help)
246331
print_usage \
247332
&& exit 0
@@ -272,10 +357,12 @@ while (( $# > 0 )); do
272357
|| exception 'Unsupported PREFIX value' 2
273358
shift 2
274359
;;
360+
-r|--member-role)
361+
MEMBER_ROLE="${2}"
362+
shift 2
363+
;;
275364
-s|--namespace)
276365
NAMESPACE="${2}"
277-
[[ "${NAMESPACE}" =~ ^[a-z0-9-]{2,}(/[a-z0-9-]{2,})*$ ]] \
278-
|| exception "Unsupported REMOTE_NAMESPACE '$NAMESPACE' dirname" 2
279366
shift 2
280367
;;
281368
-o|--output-dir)

0 commit comments

Comments
 (0)