-
Notifications
You must be signed in to change notification settings - Fork 44
73 lines (62 loc) · 2.47 KB
/
Copy pathremove-feature-snapshot.yaml
File metadata and controls
73 lines (62 loc) · 2.47 KB
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
name: Remove Feature SNAPSHOT
on:
delete:
jobs:
remove:
# Only run for feature branches
if: github.event.ref_type == 'branch' && startsWith(github.event.ref, 'feature/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Set up JDK 8
uses: actions/setup-java@v5
with:
java-version: '8'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v6
- name: Extract feature version
id: version
uses: ./.github/actions/extract-feature-version
with:
branch-name: ${{ github.event.ref }}
- name: Delete packages from GitHub Packages
env:
GH_TOKEN: ${{ secrets.CR_PAT }}
run: |
VERSION="${{ steps.version.outputs.version }}"
ORG="${{ github.repository_owner }}"
PACKAGES=(
"com.scalar-labs.scalardb"
"com.scalar-labs.scalardb-schema-loader"
"com.scalar-labs.scalardb-integration-test"
"com.scalar-labs.scalardb-data-loader-core"
"com.scalar-labs.scalardb-data-loader-cli"
)
for PACKAGE in "${PACKAGES[@]}"; do
echo "Deleting ${PACKAGE}:${VERSION}..."
# Get all versions info
VERSIONS_JSON=$(gh api \
"/orgs/${ORG}/packages/maven/${PACKAGE}/versions" 2>/dev/null || echo "[]")
VERSION_ID=$(echo "$VERSIONS_JSON" | jq -r ".[] | select(.name == \"${VERSION}\") | .id")
VERSION_COUNT=$(echo "$VERSIONS_JSON" | jq 'length')
if [ -n "$VERSION_ID" ]; then
if [ "$VERSION_COUNT" -eq 1 ]; then
# Last version - delete entire package
gh api \
--method DELETE \
"/orgs/${ORG}/packages/maven/${PACKAGE}" \
&& echo " Deleted entire package ${PACKAGE} (was last version)" \
|| { echo " Failed to delete package ${PACKAGE}"; exit 1; }
else
# Multiple versions - delete only this version
gh api \
--method DELETE \
"/orgs/${ORG}/packages/maven/${PACKAGE}/versions/${VERSION_ID}" \
&& echo " Deleted ${PACKAGE}:${VERSION}" \
|| { echo " Failed to delete ${PACKAGE}:${VERSION}"; exit 1; }
fi
else
echo " Version not found: ${PACKAGE}:${VERSION}"
fi
done