Skip to content

Commit

Permalink
Merge branch 'release'
Browse files Browse the repository at this point in the history
  • Loading branch information
petrzpav committed Mar 5, 2023
2 parents 16de107 + 6abc1b8 commit ec78429
Show file tree
Hide file tree
Showing 29 changed files with 1,093 additions and 380 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.4.0] - 2023-03-05
### Added
- Change default prefix to project_name+ instead of project_name-

### Changed
- Separate iotests to self-standing file

## [0.3.0] - 2022-09-22

## [0.2.0] - 2022-08-31
Expand All @@ -15,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Set name of distributed project as `original_project_name user_name`


[0.4.0]: https://github.com/internetguru/academy/compare/v0.3.0...v0.4.0
[0.3.0]: https://github.com/internetguru/academy/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/internetguru/academy/compare/v0.1.0...v0.2.0
[0.1.0]: https://github.com/internetguru/academy/compare/v0.0.0...v0.1.0
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ Note: To execute individual commands, [trigger their pipeline](https://docs.gitl

## GitLab CI Variables

- `ACADEMY_DASHBOARD: "URL"`
- Dashboard URL, e.g. https://academy.internetguru.io
- `ACADEMY_DEADLINE: "DATE"`
- See `--deadline` option in `academy collect` documentation.
- `ACADEMY_EDITABLE: "PATTERN"`
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.0
0.4.0
38 changes: 27 additions & 11 deletions academy
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
#!/bin/bash
#!/usr/bin/env bash

set -o pipefail

declare -r SCRIPT='academy'
# shellcheck disable=SC2155
declare -r DIR="$(dirname "${BASH_SOURCE[0]}")"
# shellcheck disable=SC2034
declare -rA LANG_TO_EXTENSION=( [java]=java [oracle]=sql )
# shellcheck disable=SC2034
declare -r SRC_DIR='src'
declare CUSTOMIZE=1
# shellcheck disable=SC1091
# shellcheck disable=SC1090
. "${DIR}/commons"
source "${DIR}/commons"
# shellcheck disable=SC1091
source "${DIR}/badges"

# disabled by LB
# check_lang "${ACADEMY_LANG}"

check_lang "${ACADEMY_LANG}"
customize_academy() {
(( CUSTOMIZE )) || return
local CUSTOM_ACADEMY='.academy'
[[ -d "${CUSTOM_ACADEMY}" ]] \
|| return
cp "${CUSTOM_ACADEMY}"/* "${DIR}"
}

# shellcheck disable=SC2155
declare WORKING_DIR="$(readlink -f ".")"
Expand All @@ -25,26 +36,31 @@ while (( $# > 0 )); do
WORKING_DIR="$(readlink -f "${2}")"
[[ -d "${WORKING_DIR}" ]] \
|| exception 'WORKING_DIR not found'
shift; shift ;;
shift 2
;;
-C|--no-customize)
CUSTOMIZE=0
shift
;;
help)
print_usage
exit
;;
collect|distribute|measure)
# shellcheck disable=SC1091
# shellcheck disable=SC1090
. "${DIR}/git_functions"
# shellcheck disable=SC1091
# shellcheck disable=SC1090
. "${DIR}/gitlab_api"
source "${DIR}/git_functions"
# check requirements
check_command git jq
;&
evaluate)
evaluate|execute)
declare -r CMD="${1}"
shift
# shellcheck disable=SC1091
source "${DIR}/gitlab_api"
customize_academy
# shellcheck disable=SC1090
. "${DIR}/${CMD}" "$@"
source "${DIR}/${CMD}" "$@"
exit $?
;;
*)
Expand Down
61 changes: 61 additions & 0 deletions badges
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

declare SHIELDS='https://img.shields.io/static/v1'
declare DEFAULT_COLOR='inactive'

# init pathnames to badges
badge_init() {
local badge_name="${1}"
local badge_default="${2}" #opt
badge_generate "${badge_name}" "${badge_default:--}"
# printf '' ... FIXME - Print badge URL
}

# % to colors
percent_to_color() {
declare color='brightgreen'
declare perc="${1%\%}"
(( 10#$perc < 85 )) \
&& color='green'
(( 10#$perc < 70 )) \
&& color='yellow'
(( 10#$perc < 55 )) \
&& color='orange'
(( 10#$perc < 45 )) \
&& color='red'
printf -- '%s\n' "${color}"
}

fraction_to_color() {
if [[ "${1}" == */0 ]]; then
printf '%s\n' "${DEFAULT_COLOR}"
return 1
fi
percent_to_color "$(( 100 * $1 ))"
}

# URL encoding
url_encode() {
jq -Rr @uri <<< "${1}"
}

# generate badge
badge_generate() {
local badge_name="${1}"
local ci_job="${CI_JOB_NAME:-local}"
local badge_file="${badge_name// /-}"
badge_file="${RESULTS:-${WORKING_DIR}/.results}/badge-${ci_job}-${badge_file,,}.svg"
local badge_label
badge_label="$( url_encode "${badge_name}" )"
local badge_value
badge_value="$( url_encode "${2}" )"
local badge_color="${3}"
[[ -z "${badge_color}" ]] \
&& case "${2}" in
n/a) badge_color="${DEFAULT_COLOR}";;
*/*) badge_color="$( fraction_to_color "${2}" )";;
*%) badge_color="$( percent_to_color "${2%\%}" )";;
*) badge_color="${DEFAULT_COLOR}"
esac
curl -so "${badge_file}" "${SHIELDS}?label=${badge_label}&message=${badge_value}&color=${badge_color}"
}
21 changes: 21 additions & 0 deletions build-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
build-docker-image:
image: docker:20.10.10
stage: build
tags:
- docker
variables:
DOCKER_HOST: tcp://dockerhost:2375/
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
services:
- name: docker:20.10.10-dind
alias: dockerhost
script:
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
- docker build --pull -t $CI_REGISTRY_IMAGE .
- docker push $CI_REGISTRY_IMAGE
rules:
- changes:
- Dockerfile
- when: manual
allow_failure: true
60 changes: 47 additions & 13 deletions collect
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

get_last_commit() {
[[ -z "${DEADLINE}" ]] \
Expand All @@ -7,13 +7,21 @@ get_last_commit() {
get_last_push
}
sync_files() {
# shellcheck disable=SC2155
local eg=$( shopt -p extglob )
shopt -s extglob
git_checkout "${user_projects_folder}/${user_project_ns}" "${last_commit}"
# shellcheck disable=SC2086
rsync -a --relative --delete \
"${user_projects_folder}/${user_project_ns}/./"${EDITABLE} "${WORKING_DIR}" \
|| exception 'Unable to rsync files'
$eg
}
create_results() {
create_results_default() {
"${DIR}/${SCRIPT}" -w "${WORKING_DIR}" --no-customize evaluate
mv "${WORKING_DIR}/.results" "${user_projects_folder}/${user_project_ns}"
}
create_results_java() {
"${DIR}/${SCRIPT}" -w "${WORKING_DIR}" evaluate
mv "${WORKING_DIR}/.results" "${user_projects_folder}/${user_project_ns}"
compile_txt="${user_projects_folder}/${user_project_ns}/.results/compile.txt"
Expand All @@ -29,14 +37,24 @@ create_results() {
echo
git_reset_hard "${user_projects_folder}/${user_project_ns}"
}
create_results() {
case "${ACADEMY_LANG}" in
java) create_results_"${ACADEMY_LANG}";;
*) create_results_default;;
esac
}
collect() {
# shellcheck disable=SC2155
[[ ! -t 0 ]] \
|| exception 'Missing stdin' 2
exec 3<&0
local user_list=()
# shellcheck disable=SC2207
user_list=( $( cat ) )
local user_i=1
acquire_token
[[ -z "${OUTPUT_DIR}" ]] \
&& OUTPUT_DIR="$(mktemp -d)"
trap 'rm -rf "${OUTPUT_DIR}"' EXIT
# shellcheck disable=SC2155
declare -r user_projects_folder="${OUTPUT_DIR}"
declare group_id
Expand All @@ -46,19 +64,28 @@ collect() {
declare checkstyle_txt
declare test_txt
declare results
declare -x user_repo
# shellcheck disable=SC2034
group_id="$(get_group_id "${NAMESPACE}" 2>/dev/null)"
[[ -z "${group_id}" ]] \
&& exception "Namespace '${NAMESPACE}' not found" 3

# Pre-collect script
# shellcheck disable=SC1090
[[ -f "${DIR}/pre-collect_${ACADEMY_LANG}" ]] \
&& . "${DIR}/pre-collect_${ACADEMY_LANG}"

# shellcheck disable=SC2013
for user_name in $(cat <&3); do
export user_name
for user_name in "${user_list[@]}"; do
user_project_name="${PREFIX}${user_name}"
user_project_ns="${NAMESPACE}/${user_project_name}"
echo "[$((user_i++))/${#user_list[@]}] ${user_project_ns}"
get_project_id "${user_project_ns}" >/dev/null \
|| continue
echo "$user_project_ns"
[[ "${DRY_RUN}" == 'true' ]] \
&& continue
user_repo="${user_projects_folder}/${user_project_ns}"
mkdir -p "${user_projects_folder}/${user_project_ns}"
git_clone "$(get_remote_url "${user_project_ns}")" "${user_projects_folder}/${user_project_ns}"
last_commit="$(get_last_commit)" \
Expand All @@ -68,14 +95,21 @@ collect() {
&& continue
sync_files
create_results
rm -rf "${user_projects_folder:?}/${user_project_ns}"
done

# Post-collect script
# shellcheck disable=SC1090
[[ -f "${DIR}/post-collect_${ACADEMY_LANG}" ]] \
&& . "${DIR}/post-collect_${ACADEMY_LANG}"

}

declare DRY_RUN='false'
declare PREFIX=''
declare NAMESPACE=''
declare EDITABLE='src/main/*.java'
declare DEADLINE=''
declare EDITABLE="${ACADEMY_EDITABLE}"
declare DEADLINE="${ACADEMY_DEADLINE}"
declare OUTPUT_DIR=''

# get options
Expand All @@ -95,27 +129,27 @@ while (( $# > 0 )); do
DEADLINE="${2}";
[[ "${DEADLINE}" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}(T[0-9]{2}:[0-9]{2}(:[0-9]{2}(Z|[+−][0-9]{2}:[0-9]{2})?)?)?$ ]] \
|| exception "Invalid deadline option"
shift; shift ;;
shift 2 ;;
-e|--editable)
EDITABLE="${2}";
[[ "${EDITABLE}" == *".."* ]] \
&& exception "Invalid editable option, contains '..'"
shift; shift ;;
shift 2 ;;
-n|--dry-run) DRY_RUN='true'; shift ;;
-o|--output-dir)
OUTPUT_DIR="${2}";
[[ -d "${OUTPUT_DIR}" ]] \
|| mkdir -p "${OUTPUT_DIR}" \
|| exception "Unable to create '${OUTPUT_DIR}' directory"
[[ -z "$(ls "${OUTPUT_DIR}/")" ]] \
|| exception "Output directory 'ls' is not empty"
shift; shift ;;
-p|--prefix) PREFIX="${2}"; shift; shift ;;
|| exception "Output directory '${OUTPUT_DIR}' is not empty"
shift 2 ;;
-p|--prefix) PREFIX="${2}"; shift 2 ;;
-s|--namespace)
NAMESPACE="${2}";
[[ "${NAMESPACE}" =~ ^[a-z0-9-]{2,}(/[a-z0-9-]{2,})*$ ]] \
|| exception "Unsupported NAMESPACE '${NAMESPACE}'" 2
shift; shift ;;
shift 2 ;;
--) shift; break ;;
*) break ;;
esac
Expand Down
10 changes: 9 additions & 1 deletion commons
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

declare MSG_OPENED='false'

Expand Down Expand Up @@ -51,6 +51,14 @@ exception() {
|| printf -- '%s [ #%d ]\n' "${message}" "${code}" >&2
exit "${code}"
}
warning() {
declare -r message="${1:-Unknown exception}"
declare -ri code=${2:-1}
(( code == 1 )) \
&& printf -- '%s in %s() [ #%d ]\n' "${message}" "${FUNCNAME[1]}" "${code}" >&2 \
|| printf -- '%s [ #%d ]\n' "${message}" "${code}" >&2
return "${code}"
}
print_usage() {
declare out
declare cmd="${CMD}"
Expand Down
12 changes: 12 additions & 0 deletions deploy-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pages:
stage: post-process
script:
- mkdir .public
- cp -r ./* .public
- rm -rf public
- mv .public public
artifacts:
paths:
- public
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
Loading

0 comments on commit ec78429

Please sign in to comment.