Skip to content

[Scheduled] Cleanup PR Workspaces #268

[Scheduled] Cleanup PR Workspaces

[Scheduled] Cleanup PR Workspaces #268

name: "[Scheduled] Cleanup PR Workspaces"
on:
schedule:
# 10pm every day except Sundays
- cron: "0 22 * * 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@cbb722410c2e876e24abbe8de2cc27693e501dcb # 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@344fef46b6edc7c46ce8b3b8b0a3ece7e77e05f0 # [email protected]
with:
terraform_version: ${{ steps.terraform_version.outputs.version }}
terraform_wrapper: false
- uses: webfactory/ssh-agent@dc588b651fe13675774614f8e6a936a468676387 # [email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY_ALLOW_LIST_REPOSITORY }}
- name: Configure Terraform OIDC AWS Credentials
uses: aws-actions/configure-aws-credentials@97834a484a5ab3c40fa9e2eb40fcf8041105a573
with:
aws-region: eu-west-1
role-to-assume: "arn:aws:iam::631181914621:role/oidc-serve-development"
role-duration-seconds: 7200
role-session-name: terraform-oidc-serve-cleanup
- 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/cleanup/workspace_cleanup.sh $(terraform-workspace-manager -protected-workspaces=true -aws-account-id=705467933182 -aws-iam-role=serve-opg-ci)
working-directory: terraform/environment
- name: install python
uses: actions/setup-python@55aad42e4674b58b2b2fb7d8e7552402d922b4e7 # [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/cleanup