Skip to content

Commit c43a2a0

Browse files
committed
refactor: 引入 1.8.2 版的 The Common Project Template 配置(支持產生並交付釋出包)
Signed-off-by: 林博仁(Buo-ren, Lin) <[email protected]>
1 parent 49c72c1 commit c43a2a0

15 files changed

+836
-176
lines changed

.editorconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ trim_trailing_whitespace = false
4141
# Markdownlint to check instead
4242
indent_size = unset
4343

44+
[*.{diff,patch}]
45+
# Trailing whitespaces are unchanged lines in patch files
46+
trim_trailing_whitespace = false
47+
4448
# Vagrant configuration file
4549
[Vagrantfile]
4650
indent_size = 2
@@ -52,3 +56,6 @@ indent_size = 2
5256
# YAML documents
5357
[*.{yml,yaml}]
5458
indent_size = 2
59+
60+
[.*.{yml,yaml}]
61+
indent_size = 2

.gitattributes

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Git path attributes configuration file
2+
#
3+
# References:
4+
#
5+
# * Git - Git Attributes
6+
# https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes
7+
# * Git - gitattributes Documentation
8+
# https://www.git-scm.com/docs/gitattributes
9+
#
10+
# Copyright 2023 林博仁(Buo-ren, Lin) <[email protected]>
11+
# SPDX-License-Identifier: CC-BY-SA-4.0
12+
13+
# Avoid exporting development files to release archive
14+
/.* export-ignore
15+
/continuous-integration/ export-ignore
16+
17+
# Keep editorconfig for ease of editing of product files
18+
/.editorconfig -export-ignore

.github/workflows/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
# workflows
22

3-
放置 GitHub Actions 的工作流程(workflow)定義檔
3+
放置 [GitHub Actions](https://github.com/features/actions) 的工作流程(workflow)定義檔
4+
5+
## 參考資料<br>Reference
6+
7+
* [Features • GitHub Actions](https://github.com/features/actions)
8+
Product page
9+
* [GitHub Actions Documentation - GitHub Docs](https://docs.github.com/en/actions)
10+
Official documentation

.github/workflows/check-potential-problems.yml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,41 @@
55
# * Workflow syntax for GitHub Actions - GitHub Docs
66
# https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions
77
#
8-
# Copyright 2021 林博仁(Buo-ren, Lin) <[email protected]>
8+
# Copyright 2022 林博仁(Buo-ren, Lin) <[email protected]>
99
# SPDX-License-Identifier: CC-BY-SA-4.0
1010
name: 檢查專案中的潛在問題
1111
on:
1212
- push
1313
jobs:
1414
check-using-precommit:
1515
name: 使用 pre-commit 檢查專案中的潛在問題
16-
runs-on: ubuntu-20.04
16+
runs-on: ubuntu-22.04
17+
env:
18+
PIP_CACHE_DIR: ${{ github.workspace }}/.cache/pip
19+
PRE_COMMIT_HOME: ${{ github.workspace }}/.cache/pre-commit
1720
steps:
1821
- name: 自版控庫取出內容
19-
uses: actions/checkout@v2
22+
uses: actions/checkout@v4
2023

21-
- name: 安裝 pre-commit
22-
run: pip3 install pre-commit
24+
- name: Configure PyPI data cache to speed up continuous integration
25+
uses: actions/cache@v3
26+
with:
27+
key: ${{ runner.os }}-pip
28+
path: ${{ env.PIP_CACHE_DIR }}
29+
30+
- name: >-
31+
Configure pre-commit data cache to speed up continuous integration
32+
uses: actions/cache@v3
33+
with:
34+
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
35+
path: ${{ env.PRE_COMMIT_HOME }}
2336
24-
- name: 使用 pre-commit 檢查專案中的所有檔案
25-
run: pre-commit run --all-files --color always
37+
- name: Running static analysis program
38+
run: |
39+
sudo ./continuous-integration/do-static-analysis.install-system-deps.sh
40+
./continuous-integration/do-static-analysis.sh
2641
27-
- name: 傳送持續整合結果告警到 Telegram 頻道
42+
- name: Send CI result notification to the Telegram channel
2843
uses: yanzay/[email protected]
2944
if: always()
3045
with:

.github/workflows/release.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Release product and their build aritfacts
2+
#
3+
# References:
4+
#
5+
# * Workflow syntax for GitHub Actions - GitHub Docs
6+
# https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions
7+
#
8+
# Copyright 2023 林博仁(Buo-ren, Lin) <[email protected]>
9+
# SPDX-License-Identifier: CC-BY-SA-4.0
10+
name: Release product and their build aritfacts
11+
on:
12+
push:
13+
tags:
14+
- v*.*.*
15+
16+
jobs:
17+
release:
18+
name: Release product and their build aritfacts
19+
runs-on: ubuntu-20.04
20+
steps:
21+
- name: Checkout content from the Git repository
22+
uses: actions/checkout@v4
23+
24+
- name: Determine the project identifier
25+
run: printf "project_id=${GITHUB_REPOSITORY##*/}\\n" >> $GITHUB_ENV
26+
27+
- name: Determine the name of the Git tag
28+
run: printf "release_tag=${GITHUB_REF##*/}\\n" >> $GITHUB_ENV
29+
30+
- name: Determine the release version string
31+
run: printf "release_version=${release_tag#v}\\n" >> $GITHUB_ENV
32+
33+
- name: Determine the release identifier
34+
run: printf "release_id=${project_id}-${release_version}\\n" >> $GITHUB_ENV
35+
36+
- name: Generate the release archive
37+
run: |-
38+
sudo ./continuous-integration/generate-build-artifacts.install-system-deps.sh
39+
./continuous-integration/generate-build-artifacts.sh
40+
41+
- name: Generate the release description
42+
run: ./continuous-integration/generate-release-description.sh
43+
44+
- name: Publish the release archive to the GitHub Releases
45+
uses: softprops/[email protected]
46+
with:
47+
name: ${{ env.project_id }} ${{ env.release_version }}
48+
files: |
49+
${{ env.release_id }}.tar*
50+
body_path: .detailed_changes

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
# https://reuse.software/
3939
!.reuse/
4040

41+
# Do track GitLab CI configuration file
42+
!/.gitlab-ci.yml
43+
4144
# Don't track common backup filename extensions
4245
*~
4346
*.bak*

.gitlab-ci.yml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
#
88
# Copyright 2023 林博仁(Buo-ren, Lin) <[email protected]>
99
# SPDX-License-Identifier: CC-BY-SA-4.0
10-
static-analysis:
10+
do-static-analysis:
1111
stage: test
12+
needs: []
1213
image: ubuntu:22.04
1314
variables:
1415
PIP_CACHE_DIR: ${CI_PROJECT_DIR}/.cache/pip
@@ -21,4 +22,41 @@ static-analysis:
2122
- ${PRE_COMMIT_HOME}
2223

2324
script:
25+
- ./continuous-integration/do-static-analysis.install-system-deps.sh
2426
- ./continuous-integration/do-static-analysis.sh
27+
28+
generate-build-artifacts:
29+
stage: build
30+
rules:
31+
- if: $CI_COMMIT_TAG
32+
needs: []
33+
image: ubuntu:22.04
34+
artifacts:
35+
paths:
36+
- ${CI_PROJECT_NAME}-*.tar*
37+
script:
38+
- ./continuous-integration/generate-build-artifacts.install-system-deps.sh
39+
- ./continuous-integration/generate-build-artifacts.sh
40+
41+
upload-release-assets:
42+
stage: deploy
43+
rules:
44+
- if: $CI_COMMIT_TAG
45+
needs:
46+
- generate-build-artifacts
47+
image: curlimages/curl:latest
48+
script:
49+
- ./continuous-integration/upload-gitlab-generic-packages.sh
50+
51+
create-release:
52+
stage: deploy
53+
rules:
54+
- if: $CI_COMMIT_TAG
55+
needs:
56+
- generate-build-artifacts
57+
- upload-release-assets
58+
image: registry.gitlab.com/gitlab-org/release-cli:latest
59+
script:
60+
- apk add bash git
61+
- ./continuous-integration/generate-release-description.sh
62+
- ./continuous-integration/create-gitlab-release.sh

.pre-commit-config.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
# Copyright 2021 林博仁(Buo-ren, Lin) <[email protected]>
99
# SPDX-License-Identifier: CC-BY-SA-4.0
1010

11-
exclude: '^continuous-integration/venv$'
12-
1311
repos:
1412
# Some out-of-the-box hooks for pre-commit
1513
# https://github.com/pre-commit/pre-commit-hooks
@@ -44,13 +42,13 @@ repos:
4442
# Check REUSE compliance
4543
# https://reuse.software/
4644
- repo: https://github.com/fsfe/reuse-tool
47-
rev: v0.12.1
45+
rev: v1.0.0
4846
hooks:
4947
- id: reuse
5048

5149
# Check YAML files
5250
# https://github.com/adrienverge/yamllint
5351
- repo: https://github.com/adrienverge/yamllint
54-
rev: v1.32.0
52+
rev: v1.30.0
5553
hooks:
5654
- id: yamllint
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) <[email protected]>
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'

0 commit comments

Comments
 (0)