Skip to content

[Scheduled] Cleanup PR Workspaces #676

[Scheduled] Cleanup PR Workspaces

[Scheduled] Cleanup PR Workspaces #676

name: "[Scheduled] Cleanup PR Workspaces"
on:
schedule:
# 9pm every day except Sundays
- cron: "0 21 * * 0-6"
permissions:
id-token: write
contents: read
security-events: none
pull-requests: none
actions: none
checks: none
deployments: none
issues: none
packages: none
repository-projects: none
statuses: none
jobs:
terraform_environment_cleanup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@6d193bf28034eafb982f37bd894289fe649468fc # pin@v3
- id: terraform_version
name: get terraform version
uses: ministryofjustice/opg-github-actions/.github/actions/[email protected]
with:
terraform_directory: terraform/environment
- uses: hashicorp/setup-terraform@1b93182764c8332e7679b2393cb307cbe7baf9dc # [email protected]
with:
terraform_version: ${{ steps.terraform_version.outputs.version }}
terraform_wrapper: false
- uses: webfactory/ssh-agent@fd34b8dee206fe74b288a5e61bc95fba2f1911eb # [email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY_ALLOW_LIST_REPOSITORY }}
- name: configure AWS credentials for terraform
uses: aws-actions/configure-aws-credentials@1ceaabc2d4208b18ff52a76e80c3a28df83f0277 # [email protected]
with:
role-to-assume: arn:aws:iam::631181914621:role/oidc-digideps-development
role-session-name: github-actions-terraform
role-duration-seconds: 7400
aws-region: eu-west-1
- name: install workspace manager
run: |
wget https://github.com/ministryofjustice/opg-terraform-workspace-manager/releases/download/v0.3.2/opg-terraform-workspace-manager_Linux_x86_64.tar.gz -O $HOME/terraform-workspace-manager.tar.gz
sudo tar -xvf $HOME/terraform-workspace-manager.tar.gz -C /usr/local/bin
sudo chmod +x /usr/local/bin/terraform-workspace-manager
- name: terraform init
run: terraform init -input=false
working-directory: terraform/environment
- name: clean up ephemeral environments
run: |
unset TF_WORKSPACE
./scripts/workspace_cleanup.sh $(terraform-workspace-manager -protected-workspaces=true -aws-account-id=248804316466 -aws-iam-role=digideps-ci)
working-directory: terraform/environment
- name: install python
uses: actions/setup-python@29a37be0a3d3e8bf5bc1eb19cd0502922f5b312a # [email protected]
with:
python-version: "3.10"
cache: "pip"
- name: clean up old task definitions
env:
REGION: eu-west-1
run: |
pip install -r requirements.txt
python cleanup_task_definitions.py
working-directory: scripts/pipeline/cleanup_task_definitions
slack_notify_failure:
name: notify of failure
uses: ./.github/workflows/_slack-notification.yml
if: ${{ failure() }}
needs:
- terraform_environment_cleanup
with:
success: no
branch: main
account: 454262938596
scheduled_task: "Environment Cleanup"
secrets: inherit