Skip to content

Commit 5053684

Browse files
committed
refactor: Migrate project to GitLab(with GitHub serving as a mirror)
Signed-off-by: 林博仁(Buo-ren, Lin) <Buo.Ren.Lin@gmail.com>
1 parent 1b6318e commit 5053684

File tree

5 files changed

+192
-4
lines changed

5 files changed

+192
-4
lines changed

.gitlab-ci.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# GitLab CI configuration file
2+
#
3+
# References:
4+
#
5+
# * `.gitlab-ci.yml` keyword reference | GitLab
6+
# https://docs.gitlab.com/ee/ci/yaml/
7+
#
8+
# Copyright 2023 林博仁(Buo-ren, Lin) <Buo.Ren.Lin@gmail.com>
9+
# SPDX-License-Identifier: CC-BY-SA-4.0
10+
do-static-analysis:
11+
stage: test
12+
rules:
13+
- if: $CI_COMMIT_TAG == null
14+
needs: []
15+
image: ubuntu:22.04
16+
variables:
17+
PIP_CACHE_DIR: ${CI_PROJECT_DIR}/.cache/pip
18+
PRE_COMMIT_HOME: ${CI_PROJECT_DIR}/.cache/pre-commit
19+
SHELLCHECK_DIR: ${CI_PROJECT_DIR}/.cache/shellcheck-stable
20+
cache:
21+
# Enable per-job and per-branch caching
22+
key: $CI_JOB_NAME-$CI_COMMIT_REF_SLUG
23+
paths:
24+
- ${PIP_CACHE_DIR}
25+
- ${PRE_COMMIT_HOME}
26+
- ${SHELLCHECK_DIR}
27+
28+
script:
29+
- ./continuous-integration/do-static-analysis.install-system-deps.sh
30+
- ./continuous-integration/do-static-analysis.sh
31+
32+
generate-build-artifacts:
33+
stage: build
34+
rules:
35+
- if: $CI_COMMIT_TAG
36+
needs: []
37+
image: ubuntu:22.04
38+
artifacts:
39+
paths:
40+
- ${CI_PROJECT_NAME}-*.tar*
41+
script:
42+
- ./continuous-integration/generate-build-artifacts.install-system-deps.sh
43+
- ./continuous-integration/generate-build-artifacts.sh
44+
45+
upload-release-assets:
46+
stage: deploy
47+
rules:
48+
- if: $CI_COMMIT_TAG
49+
needs:
50+
- generate-build-artifacts
51+
image: curlimages/curl:latest
52+
script:
53+
- ./continuous-integration/upload-gitlab-generic-packages.sh
54+
55+
create-release:
56+
stage: deploy
57+
rules:
58+
- if: $CI_COMMIT_TAG
59+
needs:
60+
- generate-build-artifacts
61+
- upload-release-assets
62+
image: registry.gitlab.com/gitlab-org/release-cli:latest
63+
script:
64+
- apk add bash git
65+
- ./continuous-integration/generate-release-description.sh
66+
- ./continuous-integration/create-gitlab-release.sh

.reuse/dep5

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
22
Upstream-Name: The Common GNU Bash Shell Script Templates
3-
Upstream-Contact: The Common GNU Bash Shell Script Templates's project issue tracker <https://github.com/the-common/bash-script-templates/issues>
4-
Source: https://github.com/the-common/bash-script-templates
3+
Upstream-Contact: The Common GNU Bash Shell Script Templates's project issue tracker <https://gitlab.com/the-common/bash-script-templates/-/issues>
4+
Source: https://gitlab.com/the-common/bash-script-templates
55

66
Files:
77
*README.md

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
Ready-to-use bash shell script templates at your fingertips!
44

5-
<https://github.com/the-common/bash-script-templates>
6-
[![GitHub Actions workflow status badge](https://github.com/the-common/bash-script-templates/actions/workflows/check-potential-problems.yml/badge.svg "GitHub Actions workflow status")](https://github.com/the-common/bash-script-templates/actions/workflows/check-potential-problems.yml) [![pre-commit enabled badge](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white "This project uses pre-commit to check potential problems")](https://pre-commit.com/) [![REUSE Specification compliance badge](https://api.reuse.software/badge/github.com/the-common/bash-script-templates "This project complies to the REUSE specification to decrease software licensing costs")](https://api.reuse.software/info/github.com/the-common/bash-script-templates)
5+
<https://gitlab.com/the-common/bash-script-templates>
6+
[![The GitLab CI pipeline status badge of the project's `main` branch](https://gitlab.com/the-common/bash-script-templates/badges/main/pipeline.svg?ignore_skipped=true "Click here to check out the comprehensive status of the GitLab CI pipelines")](https://gitlab.com/the-common/bash-script-templates/-/pipelines) [![GitHub Actions workflow status badge](https://github.com/the-common/bash-script-templates/actions/workflows/check-potential-problems.yml/badge.svg "GitHub Actions workflow status")](https://github.com/the-common/bash-script-templates/actions/workflows/check-potential-problems.yml) [![pre-commit enabled badge](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white "This project uses pre-commit to check potential problems")](https://pre-commit.com/) [![REUSE Specification compliance badge](https://api.reuse.software/badge/gitlab.com/the-common/bash-script-templates "This project complies to the REUSE specification to decrease software licensing costs")](https://api.reuse.software/info/gitlab.com/the-common/bash-script-templates)
77

88
## Reference
99

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env bash
2+
# Create GitLab project release
3+
#
4+
# Copyright 2023 林博仁(Buo-ren, Lin) <Buo.Ren.Lin@gmail.com>
5+
# SPDX-License-Identifier: CC-BY-SA-4.0
6+
7+
set \
8+
-o errexit \
9+
-o nounset
10+
11+
if ! test -v CI_PROJECT_ID; then
12+
printf \
13+
'Error: This program should be run under a GitLab CI environment.\n' \
14+
1>&2
15+
exit 1
16+
fi
17+
18+
printf \
19+
'Info: Determining release version...\n'
20+
release_version="${CI_COMMIT_TAG#v}"
21+
22+
# bash - How to get script directory in POSIX sh? - Stack Overflow
23+
# https://stackoverflow.com/questions/29832037/how-to-get-script-directory-in-posix-sh
24+
script_dir="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)"
25+
project_dir="${script_dir%/*}"
26+
27+
printf \
28+
'Info: Determining release details...\n'
29+
detailed_changes_file="${project_dir}/.detailed_changes"
30+
if ! test -e "${detailed_changes_file}"; then
31+
printf \
32+
'Error: The detailed changes file "%s" does not exist.\n' \
33+
"${detailed_changes_file}" \
34+
1>&2
35+
exit 2
36+
fi
37+
38+
release_cli_create_opts=(
39+
--name "${CI_PROJECT_TITLE} ${release_version}"
40+
--tag-name "${CI_COMMIT_TAG}"
41+
42+
# WORKAROUND: Absolute path is not accepted as file input
43+
--description "${detailed_changes_file##*/}"
44+
)
45+
46+
shopt -s nullglob
47+
for file in "${project_dir}/${CI_PROJECT_NAME}-"*; do
48+
filename="${file##*/}"
49+
package_registry_url="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}/${release_version}/${filename}"
50+
51+
release_cli_create_opts+=(
52+
--assets-link "{\"name\": \"${filename}\", \"url\": \"${package_registry_url}\"}"
53+
)
54+
done
55+
56+
printf \
57+
'Info: Creating the GitLab release...\n'
58+
if ! \
59+
release-cli create \
60+
"${release_cli_create_opts[@]}"; then
61+
printf \
62+
'Error: Unable to create the GitLab release.\n' \
63+
1>&2
64+
exit 2
65+
fi
66+
67+
printf \
68+
'Info: Operation completed without errors.\n'
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env sh
2+
# Upload release packages as GitLab generic packages
3+
#
4+
# Copyright 2023 林博仁(Buo-ren, Lin) <Buo.Ren.Lin@gmail.com>
5+
# SPDX-License-Identifier: CC-BY-SA-4.0
6+
7+
set \
8+
-o errexit \
9+
-o nounset
10+
11+
if ! test CI_PROJECT_ID; then
12+
printf \
13+
'Error: This program should be run under a GitLab CI environment.\n' \
14+
1>&2
15+
exit 1
16+
fi
17+
18+
printf \
19+
'Info: Determining release version...\n'
20+
release_version="${CI_COMMIT_TAG#v}"
21+
22+
# bash - How to get script directory in POSIX sh? - Stack Overflow
23+
# https://stackoverflow.com/questions/29832037/how-to-get-script-directory-in-posix-sh
24+
script_dir="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)"
25+
project_dir="${script_dir%/*}"
26+
27+
for file in "${project_dir}/${CI_PROJECT_NAME}-"*; do
28+
if test "${file}" == "${project_dir}/${CI_PROJECT_NAME}-*"; then
29+
# No release packages are found, avoid missing file error
30+
break
31+
fi
32+
33+
printf \
34+
'Info: Uploading the "%s" file to the GitLab generic packages registry...\n' \
35+
"${file}"
36+
37+
filename="${file##*/}"
38+
package_registry_url="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}/${release_version}/${filename}"
39+
40+
if ! \
41+
curl \
42+
--header "JOB-TOKEN: ${CI_JOB_TOKEN}" \
43+
--upload-file "${file}" \
44+
"${package_registry_url}"; then
45+
printf \
46+
'Error: Unable to upload the "%s" file to the GitLab generic packages registry.\n' \
47+
"${file}" \
48+
1>&2
49+
exit 2
50+
fi
51+
done
52+
53+
printf \
54+
'Info: Operation completed without errors.\n'

0 commit comments

Comments
 (0)