-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from svc-design/ssl-cert-workflow
add workflows: ssl cert workflow
- Loading branch information
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Generate and Release SSL Certificates | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- '.github/workflows/ssl-cert-workflow.yml' | ||
workflow_dispatch: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
generate-cert: | ||
runs-on: ubuntu-latest | ||
env: | ||
DOMAIN: 'example.com' | ||
VALID_DAYS: '365' | ||
OUTPUT_DIR: "ssl_certificates" | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Ensure script is executable | ||
run: chmod +x scripts/generate_ssl.sh | ||
|
||
- name: Generate Self-Signed Certificate | ||
run: scripts/generate_ssl.sh "$DOMAIN" "$VALID_DAYS" "$OUTPUT_DIR" | ||
shell: bash | ||
|
||
- name: Package Certificates | ||
run: | | ||
tar -czvf ssl_certificates.tar.gz -C "$OUTPUT_DIR" . | ||
- name: Upload Certificates as Artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: ssl-certificates | ||
path: ssl_certificates.tar.gz | ||
|
||
- name: Create GitHub Release | ||
id: create_release | ||
if: github.event_name == 'workflow_dispatch' | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
TAG_NAME="ssl-cert-${{ github.run_id }}" | ||
gh release create "$TAG_NAME" ssl_certificates.tar.gz --title "SSL Certificates for $DOMAIN" --notes "Generated SSL certificates for $DOMAIN valid for $VALID_DAYS days." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
|
||
# 获取参数 | ||
DOMAIN="$1" | ||
VALID_DAYS="$2" | ||
OUTPUT_DIR="$3" | ||
|
||
# 确保参数不为空 | ||
if [[ -z "$DOMAIN" || -z "$VALID_DAYS" || -z "$OUTPUT_DIR" ]]; then | ||
echo "Usage: $0 <domain_name> <valid_days> <output_dir>" | ||
exit 1 | ||
fi | ||
|
||
# 确保输出目录存在 | ||
mkdir -p "$OUTPUT_DIR" | ||
|
||
CERT_FILE="$DOMAIN.cert" | ||
KEY_FILE="$DOMAIN.key" | ||
|
||
echo "Generating certificate for domain: $DOMAIN with validity: $VALID_DAYS days" | ||
|
||
# 生成 CA 私钥 | ||
openssl genrsa -out "$OUTPUT_DIR/ca.key" 2048 | ||
|
||
# 生成 CA 证书 | ||
openssl req -x509 -new -nodes -key "$OUTPUT_DIR/ca.key" -sha256 -days "$VALID_DAYS" -out "$OUTPUT_DIR/ca.cert" -subj "/C=CN/ST=State/L=City/O=Company/OU=Org/CN=Custom-CA" | ||
|
||
# 生成服务器私钥 | ||
openssl genrsa -out "$OUTPUT_DIR/$KEY_FILE" 2048 | ||
|
||
# 生成 CSR(证书签名请求) | ||
openssl req -new -key "$OUTPUT_DIR/$KEY_FILE" -out "$OUTPUT_DIR/$DOMAIN.csr" -subj "/C=CN/ST=State/L=City/O=Company/OU=Org/CN=$DOMAIN" | ||
|
||
# 生成服务器证书 | ||
openssl x509 -req -in "$OUTPUT_DIR/$DOMAIN.csr" -CA "$OUTPUT_DIR/ca.cert" -CAkey "$OUTPUT_DIR/ca.key" -CAcreateserial -out "$OUTPUT_DIR/$CERT_FILE" -days "$VALID_DAYS" -sha256 | ||
|
||
# 清理 CSR 文件 | ||
rm -f "$OUTPUT_DIR/$DOMAIN.csr" | ||
|
||
echo "SSL Certificates for $DOMAIN generated successfully in $OUTPUT_DIR!" | ||
|