-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d55aa6
commit c8f8743
Showing
5 changed files
with
83 additions
and
159 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,79 @@ | ||
name: Terraform in Daily Test | ||
|
||
on: | ||
schedule: | ||
- cron: '0 18 * * *' # 每天 UTC 时间 18:00,即中国时间凌晨 2 点 | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check GitHub Secrets | ||
run: | | ||
if [ -z "${{ secrets.MYAPP_GITHUB_TOKEN }}" ]; then | ||
echo "GitHub Token is missing" | ||
else | ||
echo "GitHub Token is set" | ||
fi | ||
if [ -z "${{ secrets.MYAPP_USER_EMAIL }}" ]; then | ||
echo "User Email is missing" | ||
else | ||
echo "User Email is set" | ||
fi | ||
if [ -z "${{ secrets.MYAPP_USER_NAME }}" ]; then | ||
echo "User Name is missing" | ||
else | ||
echo "User Name is set" | ||
fi | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: dailyTest | ||
|
||
- name: Setup Terraform | ||
uses: hashicorp/setup-terraform@v2 | ||
with: | ||
terraform_version: 1.9.4 | ||
|
||
- name: Initialize Terraform | ||
env: | ||
TF_VAR_access_key: ${{ secrets.ALI_ACCESS_KEY }} | ||
TF_VAR_secret_key: ${{ secrets.ALI_SECRET_KEY }} | ||
TF_VAR_github_token: ${{ secrets.MYAPP_GITHUB_TOKEN }} | ||
TF_VAR_user_name: ${{ secrets.MYAPP_USER_NAME }} | ||
TF_VAR_user_email: ${{ secrets.MYAPP_USER_EMAIL }} | ||
run: terraform -chdir=./Terraform/Aliyun init | ||
|
||
- name: Apply Terraform Configuration | ||
env: | ||
TF_VAR_access_key: ${{ secrets.ALI_ACCESS_KEY }} | ||
TF_VAR_secret_key: ${{ secrets.ALI_SECRET_KEY }} | ||
TF_VAR_github_token: ${{ secrets.MYAPP_GITHUB_TOKEN }} | ||
TF_VAR_user_name: ${{ secrets.MYAPP_USER_NAME }} | ||
TF_VAR_user_email: ${{ secrets.MYAPP_USER_EMAIL }} | ||
run: terraform -chdir=./Terraform/Aliyun apply -auto-approve | ||
|
||
- name: Print current directory and file list | ||
run: | | ||
cd ./Terraform/Aliyun | ||
echo "Current directory:" | ||
pwd | ||
echo "Files in the current directory:" | ||
ls | ||
- name: Wait for 20 minutes before destroying resources | ||
run: sleep 1200 # 等待 20 分钟 | ||
|
||
- name: Destroy Terraform Configuration | ||
env: | ||
TF_VAR_access_key: ${{ secrets.ALI_ACCESS_KEY }} | ||
TF_VAR_secret_key: ${{ secrets.ALI_SECRET_KEY }} | ||
TF_VAR_github_token: ${{ secrets.MYAPP_GITHUB_TOKEN }} | ||
TF_VAR_user_name: ${{ secrets.MYAPP_USER_NAME }} | ||
TF_VAR_user_email: ${{ secrets.MYAPP_USER_EMAIL }} | ||
run: terraform -chdir=./Terraform/Aliyun destroy -auto-approve | ||
|
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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