Skip to content

Commit be0f850

Browse files
Merge pull request #38 from Githubguy132010/dev
Build-check Workflow Improvements
2 parents 816bdf5 + 1efed41 commit be0f850

File tree

6 files changed

+717
-110
lines changed

6 files changed

+717
-110
lines changed

.github/copilot-instructions.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
Guidelines for Using GitHub Copilot in Code Generation
2+
3+
Clear and Readable Code:
4+
5+
Code must be generated according to strict conventions, such as camelCase or snake_case, depending on the programming language. This is crucial for ensuring consistency, facilitating comprehension, and improving the maintainability of the code, particularly in large-scale projects.
6+
7+
Detailed and informative annotations are mandatory, with a focus on explaining complex logic and algorithms. These annotations should strike an ideal balance between completeness and conciseness, enabling team members to collaborate efficiently and onboard new team members quickly.
8+
9+
Functions and methods must be designed to maximize modularity. Each module should serve a specific responsibility, enhancing reusability and significantly simplifying bug fixes or extensions. Avoiding overly nested functions or methods helps to limit cyclomatic complexity.
10+
11+
Security Measures:
12+
13+
Generated code must not contain known vulnerabilities, such as SQL injection, buffer overflows, or hardcoded credentials. Proactively applying security measures, such as using prepared statements and avoiding vulnerable APIs, is mandatory.
14+
15+
All inputs must be thoroughly validated before being processed within the application. This includes both server-side and client-side validation. Additionally, error handling must be robust, providing clear messages and logging mechanisms that enable developers to quickly locate and resolve issues.
16+
17+
Use frameworks and libraries that enforce security automatically, such as ORMs for database interactions and modern cryptographic libraries. This minimizes the risk of human errors and promotes best practices.
18+
19+
Performance Optimization:
20+
21+
Code should be written with algorithmic efficiency in mind. This includes avoiding redundant iterations and using efficient data structures like hashmaps or balanced trees, depending on the situation.
22+
23+
Balancing readability and optimization is crucial, especially in critical applications such as real-time systems. Code must remain understandable for human reviewers without compromising performance.
24+
25+
Future scalability should be considered when making design decisions. This includes anticipating peak loads, efficiently managing system resources, and integrating load-balancing solutions when necessary.
26+
27+
Adherence to Best Practices:
28+
29+
Consistency in style and implementation within a project is essential. This includes following language-specific conventions, using linting tools to prevent stylistic errors, and avoiding unconventional coding practices that could cause confusion.
30+
31+
Applying proven principles such as SOLID (Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion) and DRY (Don't Repeat Yourself) is mandatory. These principles ensure robust and maintainable designs.
32+
33+
Avoid implementing inefficient or outdated methodologies, as these limit the flexibility and expandability of future development cycles.
34+
35+
Copyright and Licensing:
36+
37+
Copilot must not generate code that infringes on copyrights. All generated code must fall under a permissive license unless stated otherwise. This prevents legal conflicts and ensures the integrity of the project.
38+
39+
All dependencies and libraries used must be thoroughly documented. This includes specifying licensing requirements and ensuring compliance with these licenses to avoid legal risks.
40+
41+
Usability:
42+
43+
User interfaces, both CLI and GUI, must be intuitive and easy to use. Unnecessary complexity should be avoided, focusing on clear navigation and accessible features.
44+
45+
Error handling in user interfaces should aim for user-friendly messages that inform the user about the nature of the error and provide practical solutions. This significantly enhances the overall user experience.
46+
47+
Systematic implementation of internationalization (i18n) is essential to make the application accessible to a global audience. This includes supporting multiple languages and respecting regional differences in date formats, currencies, and other cultural norms.
48+
49+
Compatibility and Sustainability:
50+
51+
Generated code must remain up-to-date with the latest versions of programming languages and frameworks while maintaining backward compatibility. This promotes the sustainability of the codebase.
52+
53+
Modularity should be central to the design, allowing future changes or extensions to be implemented easily without requiring significant refactoring.
54+
55+
Version control using tools like Git, combined with automated CI/CD pipelines, must be applied to ensure a consistent and reliable codebase.
56+
57+
Documentation and Educational Value:
58+
59+
Each function must be accompanied by clear and concise documentation describing its functionality and limitations. This includes adding example implementations for practical application.
60+
61+
Project documentation, such as README files, must be detailed and provide clear guidelines for installation, usage, and troubleshooting. This facilitates adoption by new users and developers.
62+
63+
Regular updates and maintenance of documentation are essential to keep it synchronized with the evolution of the project.
64+
65+
Minimization of Dependencies:
66+
67+
External libraries should only be used when absolutely necessary. Overuse of dependencies increases the risk of security vulnerabilities and compatibility issues.
68+
69+
Core functionality must remain independent of external resources, ensuring the application’s robustness in various environments.
70+
71+
Ethical Responsibility:
72+
73+
Code must not be generated for applications that are unethical or harmful, such as malware or invasive surveillance.
74+
75+
Risky patterns and potential security issues must be explicitly flagged with warning annotations to ensure developers are aware of the implications.
76+
77+
Promoting ethics and social responsibility must be an integral part of the development culture, with attention to minimizing harmful impacts and maximizing positive societal contributions.
78+
79+
### Guidelines for Using GitHub Copilot in Code Generation
80+
81+
1. **Clear and Readable Code:**
82+
- Code must be generated according to strict conventions, such as camelCase or snake_case, depending on the programming language. This is crucial for ensuring consistency, facilitating comprehension, and improving the maintainability of the code, particularly in large-scale projects.
83+
- Detailed and informative annotations are mandatory, with a focus on explaining complex logic and algorithms. These annotations should strike an ideal balance between completeness and conciseness, enabling team members to collaborate efficiently and onboard new team members quickly.
84+
- Functions and methods must be designed to maximize modularity. Each module should serve a specific responsibility, enhancing reusability and significantly simplifying bug fixes or extensions. Avoiding overly nested functions or methods helps to limit cyclomatic complexity.
85+
86+
2. **Security Measures:**
87+
- Generated code must not contain known vulnerabilities, such as SQL injection, buffer overflows, or hardcoded credentials. Proactively applying security measures, such as using prepared statements and avoiding vulnerable APIs, is mandatory.
88+
- All inputs must be thoroughly validated before being processed within the application. This includes both server-side and client-side validation. Additionally, error handling must be robust, providing clear messages and logging mechanisms that enable developers to quickly locate and resolve issues.
89+
- Use frameworks and libraries that enforce security automatically, such as ORMs for database interactions and modern cryptographic libraries. This minimizes the risk of human errors and promotes best practices.
90+
91+
3. **Performance Optimization:**
92+
- Code should be written with algorithmic efficiency in mind. This includes avoiding redundant iterations and using efficient data structures like hashmaps or balanced trees, depending on the situation.
93+
- Balancing readability and optimization is crucial, especially in critical applications such as real-time systems. Code must remain understandable for human reviewers without compromising performance.
94+
- Future scalability should be considered when making design decisions. This includes anticipating peak loads, efficiently managing system resources, and integrating load-balancing solutions when necessary.
95+
96+
4. **Adherence to Best Practices:**
97+
- Consistency in style and implementation within a project is essential. This includes following language-specific conventions, using linting tools to prevent stylistic errors, and avoiding unconventional coding practices that could cause confusion.
98+
- Applying proven principles such as SOLID (Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion) and DRY (Don't Repeat Yourself) is mandatory. These principles ensure robust and maintainable designs.
99+
- Avoid implementing inefficient or outdated methodologies, as these limit the flexibility and expandability of future development cycles.
100+
101+
5. **Copyright and Licensing:**
102+
- Copilot must not generate code that infringes on copyrights. All generated code must fall under a permissive license unless stated otherwise. This prevents legal conflicts and ensures the integrity of the project.
103+
- All dependencies and libraries used must be thoroughly documented. This includes specifying licensing requirements and ensuring compliance with these licenses to avoid legal risks.
104+
105+
6. **Usability:**
106+
- User interfaces, both CLI and GUI, must be intuitive and easy to use. Unnecessary complexity should be avoided, focusing on clear navigation and accessible features.
107+
- Error handling in user interfaces should aim for user-friendly messages that inform the user about the nature of the error and provide practical solutions. This significantly enhances the overall user experience.
108+
- Systematic implementation of internationalization (i18n) is essential to make the application accessible to a global audience. This includes supporting multiple languages and respecting regional differences in date formats, currencies, and other cultural norms.
109+
110+
7. **Compatibility and Sustainability:**
111+
- Generated code must remain up-to-date with the latest versions of programming languages and frameworks while maintaining backward compatibility. This promotes the sustainability of the codebase.
112+
- Modularity should be central to the design, allowing future changes or extensions to be implemented easily without requiring significant refactoring.
113+
- Version control using tools like Git, combined with automated CI/CD pipelines, must be applied to ensure a consistent and reliable codebase.
114+
115+
8. **Documentation and Educational Value:**
116+
- Each function must be accompanied by clear and concise documentation describing its functionality and limitations. This includes adding example implementations for practical application.
117+
- Project documentation, such as README files, must be detailed and provide clear guidelines for installation, usage, and troubleshooting. This facilitates adoption by new users and developers.
118+
- Regular updates and maintenance of documentation are essential to keep it synchronized with the evolution of the project.
119+
120+
9. **Minimization of Dependencies:**
121+
- External libraries should only be used when absolutely necessary. Overuse of dependencies increases the risk of security vulnerabilities and compatibility issues.
122+
- Core functionality must remain independent of external resources, ensuring the application’s robustness in various environments.
123+
124+
10. **Ethical Responsibility:**
125+
- Code must not be generated for applications that are unethical or harmful, such as malware or invasive surveillance.
126+
- Risky patterns and potential security issues must be explicitly flagged with warning annotations to ensure developers are aware of the implications.
127+
- Promoting ethics and social responsibility must be an integral part of the development culture, with attention to minimizing harmful impacts and maximizing positive societal contributions.
128+

.github/workflows/build-check.yaml

Lines changed: 139 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,171 @@
1-
name: Check if ISO can be built
1+
name: Validate and Test Build
22

33
on:
44
pull_request:
55
branches:
66
- main
7+
- dev
78
workflow_dispatch:
89
schedule:
910
- cron: '0 0 * * *'
1011

12+
env:
13+
DOCKER_BUILDKIT: 1
14+
PACMAN_CACHE: /tmp/pacman-cache
15+
WORKSPACE: /workdir
16+
BUILD_DIR: /workdir/workdir
17+
OUTPUT_DIR: /workdir/out
18+
1119
jobs:
12-
build:
20+
validate:
1321
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout Repository
24+
uses: actions/checkout@v4
25+
26+
- name: Validate package list
27+
run: |
28+
# Check if package list exists
29+
if [ ! -f packages.x86_64 ]; then
30+
echo "::error::packages.x86_64 file not found"
31+
exit 1
32+
fi
33+
34+
# Check for duplicate packages
35+
sort packages.x86_64 | uniq -d > duplicates.txt
36+
if [ -s duplicates.txt ]; then
37+
echo "::error::Duplicate packages found:"
38+
cat duplicates.txt
39+
exit 1
40+
fi
41+
42+
# Validate package names exist in Arch repos
43+
docker run --rm -v "${{ github.workspace }}/packages.x86_64:/packages.x86_64:ro" archlinux:latest bash -c "
44+
set -euo pipefail
45+
pacman -Syu --noconfirm
46+
while read -r pkg; do
47+
[[ \$pkg =~ ^# ]] && continue
48+
[[ -z \$pkg ]] && continue
49+
if ! pacman -Si \$pkg >/dev/null 2>&1; then
50+
echo \"::error::Package not found: \$pkg\"
51+
exit 1
52+
fi
53+
done < /packages.x86_64
54+
"
1455
56+
security-scan:
57+
runs-on: ubuntu-latest
1558
steps:
1659
- name: Checkout Repository
1760
uses: actions/checkout@v4
1861

62+
- name: Run Security Scan
63+
uses: aquasecurity/trivy-action@master
64+
with:
65+
scan-type: 'fs'
66+
ignore-unfixed: true
67+
format: 'sarif'
68+
output: 'trivy-results.sarif'
69+
severity: 'CRITICAL,HIGH'
70+
71+
- name: Upload Scan Results
72+
uses: github/codeql-action/upload-sarif@v2
73+
if: always()
74+
with:
75+
sarif_file: 'trivy-results.sarif'
76+
77+
test-build:
78+
needs: [validate, security-scan]
79+
runs-on: ubuntu-latest
80+
timeout-minutes: 120
81+
82+
steps:
83+
- name: Checkout Repository
84+
uses: actions/checkout@v4
85+
86+
- name: Cache Pacman packages
87+
uses: actions/cache@v3
88+
with:
89+
path: ${{ env.PACMAN_CACHE }}
90+
key: pacman-${{ runner.os }}-${{ github.sha }}
91+
restore-keys: |
92+
pacman-${{ runner.os }}-
93+
1994
- name: Set up Arch Linux Container
2095
run: |
21-
docker run --privileged --name arch-container -d -v ${{ github.workspace }}:/workdir archlinux:latest sleep infinity
96+
mkdir -p ${{ env.PACMAN_CACHE }}
97+
docker run --privileged --name arch-container -d \
98+
-v ${{ github.workspace }}:${{ env.WORKSPACE }} \
99+
-v ${{ env.PACMAN_CACHE }}:/var/cache/pacman/pkg \
100+
archlinux:latest sleep infinity
22101
23-
- name: Build ISO in Arch Container
102+
- name: Install Dependencies
24103
run: |
25104
docker exec arch-container bash -c "
26-
pacman -Syu --noconfirm &&
27-
pacman -S --noconfirm git archiso grub &&
28-
cd /workdir &&
29-
mkarchiso -v -w workdir/ -o out/ .
105+
set -euo pipefail
106+
pacman -Syu --noconfirm
107+
pacman -S --noconfirm --needed git archiso grub
30108
"
31109
32-
- name: Rename ISO to Arch.iso
110+
- name: Test Build
111+
id: build
33112
run: |
34113
docker exec arch-container bash -c "
35-
iso_file=\$(ls /workdir/out/*.iso 2>/dev/null | head -n 1) &&
36-
[ -n \"\$iso_file\" ] && mv \$iso_file /workdir/out/Arch.iso || echo 'No ISO file found.'
114+
set -euo pipefail
115+
cd ${{ env.WORKSPACE }}
116+
rm -rf ${{ env.BUILD_DIR }} ${{ env.OUTPUT_DIR }}
117+
mkdir -p ${{ env.BUILD_DIR }} ${{ env.OUTPUT_DIR }}
118+
mkarchiso -v -w ${{ env.BUILD_DIR }} -o ${{ env.OUTPUT_DIR }} .
37119
"
38120
39-
- name: Copy ISO to Host
121+
- name: Verify ISO
40122
run: |
41-
docker cp arch-container:/workdir/out/Arch.iso ${{ github.workspace }}/ || echo 'Failed to copy ISO to host.'
42-
43-
- name: Get current date
44-
id: date
45-
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
123+
docker exec arch-container bash -c "
124+
set -euo pipefail
125+
cd ${{ env.OUTPUT_DIR }}
126+
127+
# Check if ISO exists
128+
iso_count=\$(ls -1 *.iso 2>/dev/null | wc -l)
129+
if [ \$iso_count -eq 0 ]; then
130+
echo '::error::No ISO file found'
131+
exit 1
132+
elif [ \$iso_count -gt 1 ]; then
133+
echo '::error::Multiple ISO files found'
134+
exit 1
135+
fi
136+
137+
iso_file=\$(ls *.iso)
138+
139+
# Check ISO size (minimum 500MB)
140+
size=\$(stat -c%s \"\$iso_file\")
141+
if [ \$size -lt 524288000 ]; then
142+
echo \"::error::ISO file too small: \$((\$size / 1024 / 1024))MB\"
143+
exit 1
144+
fi
145+
146+
# Verify ISO checksum
147+
sha256sum \"\$iso_file\" > checksum.sha256
148+
sha256sum -c checksum.sha256 || {
149+
echo '::error::ISO checksum verification failed'
150+
exit 1
151+
}
152+
"
46153
47-
- name: Create GitHub Release
48-
id: create_release
49-
uses: actions/[email protected]
50-
env:
51-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52-
with:
53-
tag_name: v${{ github.run_id }}-release
54-
release_name: "Arch Linux Release"
55-
body: "Arch Linux ISO built on ${{ steps.date.outputs.date }}"
56-
draft: false
57-
prerelease: false
58-
59-
- name: Upload ISO to GitHub Release
60-
uses: actions/upload-release-asset@v1
61-
env:
62-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63-
with:
64-
upload_url: ${{ steps.create_release.outputs.upload_url }}
65-
asset_path: ${{ github.workspace }}/Arch.iso
66-
asset_name: Arch.iso
67-
asset_content_type: application/octet-stream
68-
69-
- name: Delete GitHub Release
70-
env:
71-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72-
run: |
73-
release_id=$(curl -s \
74-
-H "Authorization: token $GITHUB_TOKEN" \
75-
-H "Accept: application/vnd.github.v3+json" \
76-
https://api.github.com/repos/${{ github.repository }}/releases/tags/v${{ github.run_id }}-release | jq -r .id) &&
77-
curl -X DELETE \
78-
-H "Authorization: token $GITHUB_TOKEN" \
79-
-H "Accept: application/vnd.github.v3+json" \
80-
https://api.github.com/repos/${{ github.repository }}/releases/$release_id
81-
82-
- name: Delete Git Tag
83-
env:
84-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
154+
- name: Clean Up
155+
if: always()
85156
run: |
86-
curl -X DELETE \
87-
-H "Authorization: token $GITHUB_TOKEN" \
88-
-H "Accept: application/vnd.github.v3+json" \
89-
https://api.github.com/repos/${{ github.repository }}/git/refs/tags/v${{ github.run_id }}-release
157+
if docker ps -a | grep -q arch-container; then
158+
docker stop arch-container || true
159+
docker rm -f arch-container || true
160+
fi
161+
sudo rm -rf ${{ env.BUILD_DIR }} ${{ env.OUTPUT_DIR }}
90162
91-
- name: Clean Up
163+
- name: Report Status
164+
if: always()
92165
run: |
93-
docker stop arch-container || echo 'Failed to stop the container.'
94-
docker rm arch-container || echo 'Failed to remove the container.'
166+
if [ "${{ job.status }}" = "success" ]; then
167+
echo "✅ Build check passed successfully"
168+
else
169+
echo "❌ Build check failed"
170+
exit 1
171+
fi

0 commit comments

Comments
 (0)