Skip to content

Commit 4910177

Browse files
authored
Merge pull request #2 from ha-lizard/refactor-dir-structure
refactor dir structure
2 parents 0aef513 + 079dea8 commit 4910177

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1357
-0
lines changed

.editorconfig

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Root EditorConfig file
2+
root = true
3+
4+
# General settings for all files
5+
[*]
6+
charset = utf-8 # Use UTF-8 encoding
7+
end_of_line = lf # Use LF for line endings (Unix-style)
8+
insert_final_newline = true # Ensure the file ends with a newline
9+
trim_trailing_whitespace = true # Remove trailing whitespace on save
10+
11+
# Specific settings for Bash scripts (without extensions)
12+
[src/scripts/*]
13+
indent_style = space # Use spaces for indentation (Google Shell Guide recommends 2 spaces)
14+
indent_size = 2 # Google Shell Guide uses 2 spaces for indentation
15+
insert_final_newline = true # Ensure a final newline for scripts
16+
trim_trailing_whitespace = true # Remove trailing whitespace
17+
18+
# Bash shell style settings following Google Shell Style Guide:
19+
# - No tabs, always use 2 spaces for indentation.
20+
# - Place opening brace `{` on the same line as the function definition or loop.
21+
# - Use lowercase with underscores for variable names.
22+
# - Use `"$@"` instead of "$*" in loops or function calls to preserve arguments.
23+
# - Use `[[` for condition tests instead of `[`, and quote variables to prevent word splitting.
24+
25+
# Specific settings for Python scripts
26+
[*.py]
27+
indent_style = space # Use spaces for indentation (PEP 8 recommends 4 spaces)
28+
indent_size = 4 # Standard Python indentation (PEP 8: 4 spaces)
29+
insert_final_newline = true # Ensure a final newline
30+
trim_trailing_whitespace = true # Remove trailing whitespace
31+
max_line_length = 79 # PEP 8: Limit to 79 characters per line
32+
quote_type = single # Use single quotes for string literals (Python convention)
33+
34+
# Settings for Markdown files
35+
[*.md]
36+
max_line_length = 80 # Wrap Markdown files at 80 characters
37+
trim_trailing_whitespace = false # Allow trailing whitespace (for Markdown formatting)
38+
39+
# Settings for YAML files
40+
[*.yml]
41+
indent_style = space # Use spaces for indentation
42+
indent_size = 2 # YAML convention is 2 spaces
43+
44+
# Git configuration and related files
45+
[*.gitignore]
46+
trim_trailing_whitespace = false

.github/ISSUE_TEMPLATE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Description of the issue
2+
3+
<!-- A clear and concise description of what the issue is. -->
4+
5+
## Steps to reproduce
6+
7+
1. <!-- Step 1 -->
8+
2. <!-- Step 2 -->
9+
3. <!-- Step 3 -->
10+
11+
## Expected behavior
12+
13+
<!-- What you expected to happen -->
14+
15+
## Actual behavior
16+
17+
<!-- What actually happened -->
18+
19+
## Additional context
20+
21+
<!-- Add any other context about the problem here, including environment details (OS, Bash version, etc.). -->

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## Description
2+
3+
<!-- Provide a concise summary of your changes and the related issue(s). -->
4+
5+
## Type of change
6+
7+
- [ ] Bug fix
8+
- [ ] New feature
9+
- [ ] Documentation update
10+
- [ ] Other (please describe):
11+
12+
## Checklist
13+
14+
- [ ] I have read the project's CONTRIBUTING.md.
15+
- [ ] I have verified that my changes work as expected.
16+
- [ ] I have added or updated relevant documentation (if necessary).
17+
- [ ] I have added tests to cover my changes (if applicable).
18+
- [ ] All tests pass locally.
19+
20+
## Related Issues
21+
22+
<!-- List issues this PR closes, e.g., "Closes #123". -->
23+
24+
## Additional Notes
25+
26+
<!-- Add any additional context or screenshots about the pull request here. -->

.github/workflows/release-rpm.yml

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: Build, Sign, and Publish SRPM and RPM on Release
2+
3+
on:
4+
release:
5+
types: [published] # Trigger when a new release is published
6+
7+
jobs:
8+
build-rpm:
9+
runs-on: ubuntu-latest
10+
11+
env:
12+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13+
ACTIONS_RUNNER_DEBUG: false
14+
15+
steps:
16+
# Step 1: Checkout the code
17+
- name: Checkout Code
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0 # Fetch all history for commit count
21+
22+
# Step 2: Set up the build environment
23+
- name: Set Up Build Environment
24+
run: |
25+
set -euo pipefail
26+
27+
# Install required dependencies
28+
sudo apt update
29+
sudo DEBIAN_FRONTEND=noninteractive apt install -y rpm gnupg gh
30+
31+
# Create rpmbuild directory structure
32+
echo "Setting up rpmbuild directory structure"
33+
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
34+
35+
# Move spec files into the build structure
36+
cp -R rpm/SPECS/*.spec ~/rpmbuild/SPECS/
37+
38+
# Create the source archive
39+
cd src
40+
tar --exclude='./.git' --exclude='./rpm/SPECS' -czf ~/rpmbuild/SOURCES/iscsi-ha.tar.gz .
41+
cd ..
42+
43+
# Step 3: Extract version and release information
44+
- name: Extract Version and Release
45+
id: versioning
46+
run: |
47+
set -euo pipefail
48+
49+
# Get the release tag name from GitHub event data
50+
TAG_NAME="${{ github.event.release.tag_name }}"
51+
52+
# Extract the version (numeric part before any dash)
53+
VERSION=$(echo "$TAG_NAME" | sed -E 's/^v([0-9]+\.[0-9]+\.[0-9]+)(-.*)?$/\1/')
54+
55+
# Initialize prerelease variable
56+
PRERELEASE=""
57+
58+
# Check if the tag contains prerelease markers or if the release is marked as a prerelease
59+
if [[ "$TAG_NAME" =~ -(rc|RC|beta|BETA) ]]; then
60+
PRERELEASE=$(echo "$TAG_NAME" | sed -E 's/^.*-(rc|RC|beta|BETA).*$/\1/')
61+
elif [[ "${{ github.event.release.prerelease }}" == "true" ]]; then
62+
PRERELEASE="rc"
63+
fi
64+
65+
# Get the number of commits to use as the release number
66+
RELEASE_NUMBER=$(git rev-list --count HEAD)
67+
68+
# Combine the prerelease, and release number into the final RELEASE
69+
if [ -n "$PRERELEASE" ]; then
70+
RELEASE="${PRERELEASE}${RELEASE_NUMBER}"
71+
else
72+
RELEASE="${RELEASE_NUMBER}"
73+
fi
74+
75+
echo "VERSION=${VERSION}" >> $GITHUB_ENV
76+
echo "RELEASE=${RELEASE}" >> $GITHUB_ENV
77+
78+
# Step 4: Build RPM package
79+
- name: Build SRPM and RPM Package
80+
run: |
81+
set -euo pipefail
82+
83+
# Replace placeholders in spec files with actual version and release
84+
sed -i "s/__VERSION__/${VERSION}/g" ~/rpmbuild/SPECS/*.spec
85+
sed -i "s/__RELEASE__/${RELEASE}/g" ~/rpmbuild/SPECS/*.spec
86+
87+
# Build the RPM package
88+
rpmbuild -ba ~/rpmbuild/SPECS/*.spec
89+
90+
# Step 5: Import GPG Key
91+
- name: Import GPG Key
92+
run: |
93+
set -euo pipefail
94+
95+
# Import the private key from secrets
96+
echo "Importing GPG key"
97+
echo "${{ secrets.GPG_PRIVATE_KEY }}" | gpg --batch --import
98+
99+
# Ensure the trust level is set to ultimate for the imported key
100+
echo "Setting trust level for GPG key"
101+
echo -e "5\ny\n" | gpg --batch --command-fd 0 --edit-key "${{ secrets.GPG_KEY_ID }}" trust
102+
103+
# Step 6: Sign RPMs
104+
- name: Sign RPMs
105+
run: |
106+
set -euo pipefail
107+
108+
# Configure GPG_TTY to avoid warnings
109+
export GPG_TTY=$(tty) || true
110+
111+
# Configure RPM to use the GPG key
112+
echo "%_signature gpg" >> ~/.rpmmacros
113+
echo "%_gpg_name ${{ secrets.GPG_KEY_ID }}" >> ~/.rpmmacros
114+
115+
# Sign all RPMs
116+
find ~/rpmbuild/RPMS/ -name "*.rpm" -exec rpmsign --addsign {} \;
117+
find ~/rpmbuild/SRPMS/ -name "*.rpm" -exec rpmsign --addsign {} \;
118+
119+
# Step 7: Upload RPM and SRPM to the GitHub Release
120+
- name: Upload SRPM and RPM to GitHub Release
121+
run: |
122+
set -euo pipefail
123+
124+
# Upload binary RPMs
125+
gh release upload "${{ github.event.release.tag_name }}" ~/rpmbuild/RPMS/**/*.rpm --clobber
126+
127+
# Upload source RPM
128+
gh release upload "${{ github.event.release.tag_name }}" ~/rpmbuild/SRPMS/*.src.rpm --clobber

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Ignore log files and temporary files
2+
*.log
3+
*.tmp
4+
5+
# Ignore compiled binaries
6+
*.out
7+
*.o
8+
9+
# Ignore user-specific files
10+
.DS_Store
11+
.idea/
12+
*.swp
13+
14+
# Ignore shell history backups
15+
*.bak
16+
17+
# Ignore environment files
18+
.env
19+
.env.local
20+
21+
# Ignore test coverage and reports
22+
coverage/
23+
*.gcov

.pre-commit-config.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
---
4+
5+
exclude: "docs/_build/"
6+
7+
repos:
8+
- repo: https://github.com/pre-commit/pre-commit-hooks
9+
rev: v5.0.0
10+
hooks:
11+
- id: trailing-whitespace
12+
- id: end-of-file-fixer
13+
- id: check-json
14+
- id: check-toml
15+
- id: check-xml
16+
- id: check-yaml
17+
- id: debug-statements
18+
- id: check-builtin-literals
19+
- id: check-case-conflict
20+
- id: check-docstring-first
21+
- id: detect-private-key
22+
- id: mixed-line-ending
23+
- id: check-added-large-files
24+
25+
- repo: https://github.com/shellcheck-py/shellcheck-py
26+
rev: v0.10.0.1
27+
hooks:
28+
- id: shellcheck
29+
30+
- repo: https://github.com/scop/pre-commit-shfmt
31+
rev: v3.10.0-2
32+
hooks:
33+
- id: shfmt

.vscode/extensions.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"recommendations": [
3+
"aaron-bond.better-comments",
4+
"coolbear.systemd-unit-file",
5+
"davidanson.vscode-markdownlint",
6+
"editorconfig.editorconfig",
7+
"foxundermoon.shell-format",
8+
"gruntfuggly.todo-tree",
9+
"ms-python.autopep8",
10+
"streetsidesoftware.code-spell-checker",
11+
"timonwong.shellcheck"
12+
]
13+
}

.vscode/settings.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"editor.tabSize": 2,
3+
"editor.insertSpaces": true,
4+
"editor.trimAutoWhitespace": true,
5+
"editor.rulers": [80],
6+
"editor.formatOnSave": true,
7+
"files.trimTrailingWhitespace": true,
8+
"files.insertFinalNewline": true,
9+
"files.autoSave": "onWindowChange",
10+
11+
"[shellscript]": {
12+
"editor.tabSize": 2,
13+
"editor.insertSpaces": true,
14+
"files.eol": "\n",
15+
"editor.formatOnSave": true
16+
},
17+
18+
"[python]": {
19+
"editor.tabSize": 4,
20+
"editor.insertSpaces": true,
21+
"editor.defaultFormatter": "ms-python.autopep8",
22+
"editor.formatOnSave": true
23+
},
24+
25+
"[markdown]": {
26+
"editor.tabSize": 2,
27+
"editor.insertSpaces": true
28+
},
29+
30+
"[git-commit]": {
31+
"editor.tabSize": 2,
32+
"editor.insertSpaces": true
33+
},
34+
35+
"cSpell.words": [
36+
"addsign",
37+
"autoselect",
38+
"Autoselect",
39+
"createrepo",
40+
"elif",
41+
"github",
42+
"GITHUB",
43+
"gnupg",
44+
"hyperconverged",
45+
"iscsi",
46+
"mailx",
47+
"Massimo",
48+
"multipathd",
49+
"networkctl",
50+
"noninteractive",
51+
"pipefail",
52+
"rpmbuild",
53+
"rpmmacros",
54+
"RPMS",
55+
"rpmsign",
56+
"sendmail",
57+
"shellcheck",
58+
"smartctl",
59+
"SRPM",
60+
"SRPMS",
61+
"XAPI"
62+
],
63+
"ansible.python.interpreterPath": "/bin/python3"
64+
}

0 commit comments

Comments
 (0)