Skip to content

Workflow file for this run

name: Start and Stop Workflow
on:
schedule:
# At 08:00 PM JST
- cron: '0 11 * * 6,0'
# At 02:00 AM JST
- cron: '0 17 * * 6,0'
repository_dispatch:
types: [start, stop]
env:
SLACK_USERNAME: DeployBot
SLACK_ICON: https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png
SLACK_WEBHOOK: https://hooks.slack.com/services/${{secrets.WEBHOOK_PATH}}
TF_VAR_WEBHOOK_PATH: ${{ secrets.WEBHOOK_PATH }}
TF_VERSION: 1.7.5
AWS_REGION: ap-northeast-1
defaults:
run:
working-directory: ./terraform/scheduling
jobs:
scheduled_job:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/minecraft-test-github-actions
role-session-name: github-actions-test-session
aws-region: ${{ env.AWS_REGION }}
- name: Create Mapping Yaml
run: |
cat << EOF > secrets.yaml
OPS: ${{ secrets.WHITELIST_PLAYERS }}
WHITELIST: ${{ secrets.WHITELIST_PLAYERS }}
WEBHOOK_PATH: ${{ secrets.WEBHOOK_PATH }}
S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }}
S3_PREFIX_NAME: ${{ secrets.S3_PREFIX_NAME }}
FILTERING_STRINGS: ${{ secrets.FILTERING_STRINGS }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
EOF
- name: terraform setup
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TF_VERSION }}
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Run start.sh at 20 PM
if: github.event.schedule == '0 11 * * 6,0'
run: |
terraform init -lock=false
terraform apply -lock=false \
-var set_recovery_point=false \
-var set_seed_value=false \
-auto-approve
- name: Run stop.sh at 2 AM
if: github.event.schedule == '0 17 * * 6,0'
run: |
terraform init -lock=false
terraform destroy -lock=false -auto-approve
- name: Execute terraform on dispatch
if: github.event_name == 'repository_dispatch'
run: |
terraform init -lock=false
if [ "${{ github.event.action }}" == "start" ]; then
terraform apply -lock=false \
-var set_recovery_point=false \
-var set_seed_value=false \
-auto-approve
elif [ "${{ github.event.action }}" == "stop" ]; then
terraform destroy -lock=false -auto-approve
fi
- name: Slack Notification on Success
uses: rtCamp/action-slack-notify@v2
if: ${{ success() }}
env:
SLACK_TITLE: Deploy / Success
SLACK_COLOR: good
SLACK_MESSAGE: terraform command execution success🚀
- name: Slack Notification on Failure
uses: rtCamp/action-slack-notify@v2
if: ${{ failure() }}
env:
SLACK_TITLE: Deploy / Failure
SLACK_COLOR: danger
SLACK_MESSAGE: terraform command execution failure😢