Skip to content

update

update #9

name: Compile SELinux Policy
on:
push:
branches:
- main
paths:
- 'logrotate/selinux-policy/ee-logrotate.te'
- '.github/workflows/compile-ee-logrotate-sepolicy.yml'
workflow_dispatch:
jobs:
compile-policy:
# Chạy trên máy chủ Ubuntu mặc định, không dùng container
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
# Bước này sẽ tải code về và bao gồm lịch sử Git đầy đủ
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install SELinux build tools and Git
# Cài đặt các gói cần thiết bằng apt-get trên Ubuntu
run: sudo apt-get update && sudo apt-get install -y policycoreutils selinux-policy-dev make git
- name: Compile and package SELinux policy
run: |
# Di chuyển vào thư mục chứa file .te
cd logrotate/selinux-policy/
# Bước 1: Biên dịch file .te thành .mod
echo "Compiling ee-logrotate.te to ee-logrotate.mod..."
checkmodule -M -m -o ee-logrotate.mod ee-logrotate.te
# Bước 2: Tạo policy package (.pp) từ file .mod
echo "Creating ee-logrotate.pp from ee-logrotate.mod..."
semodule_package -o ee-logrotate.pp -m ee-logrotate.mod
- name: Get the latest tag
id: get_tag
run: |
latest_tag=$(git describe --tags --abbrev=0)
echo "latest_tag=${latest_tag}" >> $GITHUB_OUTPUT
echo "📌 Latest tag: ${latest_tag}"
- name: Upload compiled policy file to release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Di chuyển file .pp về thư mục gốc để dễ dàng upload
cp logrotate/selinux-policy/ee-logrotate.pp .
gh release upload ${{ steps.get_tag.outputs.latest_tag }} ee-logrotate.pp --clobber
echo "✅ Successfully uploaded ee-logrotate.pp to release '${{ steps.get_tag.outputs.latest_tag }}'"
- name: Commit and push compiled policy to repository
run: |
# Cấu hình git
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
# Di chuyển file .pp vào thư mục mong muốn (nếu cần)
# Ở đây giữ nguyên trong thư mục logrotate/selinux-policy/
# Thêm file .pp vào staging
git add logrotate/selinux-policy/ee-logrotate.pp
# Kiểm tra xem có thay đổi nào để commit không
if git diff --staged --quiet; then
echo "No changes to commit"
else
# Commit và push
git commit -m "ci: auto-compiled SELinux policy [skip ci]"
git push
echo "✅ Successfully committed and pushed ee-logrotate.pp to repository"
fi