-
Notifications
You must be signed in to change notification settings - Fork 6
77 lines (74 loc) · 3.03 KB
/
delete-old-releases.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: "9. Delete old Pre-Releases and tags"
on:
schedule:
# Run at 00:00 twice a month.
# https://pubs.opengroup.org/onlinepubs/9699919799/utilities/crontab.html#tag_20_25_07
- cron: '0 0 6,20 * *'
# Allow manual triggering
workflow_dispatch:
inputs:
dry_run:
description: 'Always do a dry-run first'
required: true
type: boolean
default: true
older_than:
description: 'Delete pre-releases published older than this many days ago'
required: true
type: string
default: 45
keep_latest:
description: 'Number of latest pre-releases to keep'
required: true
type: string
default: 10
tag_pattern:
description: 'Pre-releases matching this git tag regex pattern'
required: true
type: string
default: ^v
jobs:
gate-check:
# Adding an `if:` that evaluates to false for this gate-check job prevents other dependent jobs from running.
runs-on: ubuntu-latest
steps:
- id: checkUserMember
# Only check for manual runs, not scheduled runs
if: github.event_name == 'workflow_dispatch'
uses: tspascoal/[email protected]
with:
username: ${{ github.actor }}
team: 'vro-restricted'
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN_READ_TEAM }}
- name: "Check permission"
id: check-permission
# Only check for manual runs, not scheduled runs
if: github.event_name == 'workflow_dispatch'
run: |
echo "${{ github.actor }} isTeamMember: ${{ steps.checkUserMember.outputs.isTeamMember }}"
echo "Member of teams: ${{ steps.checkUserMember.outputs.teams }}"
if [ "${{ steps.checkUserMember.outputs.isTeamMember }}" = 'false' ]; then
echo "Only VRO-RESTRICTED team members can run this action!" | tee -a "$GITHUB_STEP_SUMMARY"
exit 3
fi
delete_releases:
needs: gate-check
# Deletions in public repo will be automatically propagated to internal repo when mirror.yml runs, at which point:
# - Git release tags (associated with GitHub pre-releases) will be deleted in the internal repo
# - Tag deletions will result in GitHub releases disappearing in internal repo: https://github.com/department-of-veterans-affairs/abd-vro-internal/releases
# but the number of releases (shown on the front page) is incorrect (i.e., there are orphaned GH releases)
# Submitted bug report to GitHub: https://support.github.com/ticket/personal/0/2247467
if: github.repository == 'department-of-veterans-affairs/abd-vro'
runs-on: ubuntu-latest
steps:
- name: "Delete old releases in GHCR"
uses: yoomlam/[email protected]
with:
dry_run: ${{ inputs.dry_run || false }}
delete_tags: true
pre_release_only: true
keep_latest: ${{ inputs.keep_latest || 10 }}
older_than: ${{ inputs.older_than || 45 }}
delete_tag_pattern: ${{ inputs.tag_pattern || '^v' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}