Skip to content

.github/workflows/ci-clean-up-cloud-non-production-artifacts.yaml #36

.github/workflows/ci-clean-up-cloud-non-production-artifacts.yaml

.github/workflows/ci-clean-up-cloud-non-production-artifacts.yaml #36

defaults:
run:
shell: bash
jobs:
clean-up-artifacts:
env:
BOOTSTRAP_STORAGE_PATH_NONPRODUCTION: ${{vars.BOOTSTRAP_STORAGE_PATH_NONPRODUCTION}}
EVENT_REF: ${{github.event.ref}}
HELM_CHART_REGISTRY_NONPRODUCTION: ${{vars.HELM_CHART_REGISTRY_NONPRODUCTION}}
if: |-
${{
github.event.ref_type == 'branch' &&
github.repository == 'cloudnative-team/liferay-portal' &&
(
startsWith(github.event.ref, 'LCD-') ||
startsWith(github.event.ref, 'release/')
)
}}
runs-on: ubuntu-latest
steps:
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v3
with:
project_id: ${{vars.GCP_PROJECT_ID_EXTERNAL_NONPRODUCTION}}
workload_identity_provider: ${{vars.GCP_WORKLOAD_IDENTITY_PROVIDER_EXTERNAL_NONPRODUCTION}}
- name: Set up Google Cloud CLI
uses: google-github-actions/setup-gcloud@v2
with:
project_id: ${{vars.GCP_PROJECT_ID_EXTERNAL_NONPRODUCTION}}
- name: Clean up Helm chart images
run: |
set -o errexit
set -o nounset
set -o pipefail
function main {
local registry_path="${HELM_CHART_REGISTRY_NONPRODUCTION}/$(echo "${EVENT_REF}" | tr 'A-Z/' 'a-z-')"
local images
images=$(gcloud artifacts docker images list "${registry_path}" --format="value(package)" | sort --unique) || true
local image
for image in ${images}
do
gcloud artifacts docker images delete "${image}" --delete-tags --quiet || true
done
}
main "${@}"
- name: Clean up bootstrap tarballs
run: |
set -o errexit
set -o nounset
set -o pipefail
function main {
gcloud storage rm --recursive "${BOOTSTRAP_STORAGE_PATH_NONPRODUCTION}/$(echo "${EVENT_REF}" | tr '/' '-')/" || true
}
main "${@}"
on:
delete
permissions:
contents: read
id-token: write