-
Notifications
You must be signed in to change notification settings - Fork 13
79 lines (65 loc) · 2.56 KB
/
upload.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
78
79
name: Upload Changed Modules
on:
push:
branches:
- "main"
jobs:
get_changed_folders:
runs-on: ubuntu-latest
outputs:
changed_dirs: ${{ steps.find_dirs.outputs.changed_dirs }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Find Directories with 'kcl.mod' and 'src'
id: find_dirs
run: |
# Get changed files.
dirs=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | awk -F'/' '{print $1"/"$2}' | sort -u | uniq)
# Check current file tree.
tree .
# Find directories containing 'kcl.mod' file and 'src' dir.
matching_dirs=()
for dir in $(echo "$dirs" | tr '\n' ' '); do
echo "Checking $dir"
set +e
if [ -f "$dir/kcl.mod" ] && [ -d "$dir/src" ]; then
echo "Found $dir"
matching_dirs+=("$dir")
fi
set -e
done
# Print found changed module paths.
echo "Found changed module paths: ${matching_dirs[@]}"
echo "changed_dirs=${matching_dirs[@]}" >> "$GITHUB_OUTPUT"
push_modules:
needs: [ get_changed_folders ]
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Kusion CLI
run: curl https://www.kusionstack.io/scripts/install.sh | sh -s 0.12.0-rc.3
- name: Upload Modules
env:
PACKAGE_TOKEN: '${{ secrets.PACKAGE_TOKEN }}'
run: |
# Get changed module directories.
dirs_changed="${{ needs.get_changed_folders.outputs.changed_dirs }}"
echo "Changed modules paths: ${dirs_changed[@]}"
# Manually source the Kusion environment variables.
source "$HOME/.kusion/.env"
# Get the current absolute path.
current_abs_path=$(pwd)
# Push modules to the GitHub Packages.
for dir in ${dirs_changed[@]}; do
cd "$current_abs_path/$dir"
kusion mod push . oci://ghcr.io/kusionstack --os-arch=darwin/amd64 --creds $PACKAGE_TOKEN --latest=true
kusion mod push . oci://ghcr.io/kusionstack --os-arch=darwin/arm64 --creds $PACKAGE_TOKEN --latest=true
kusion mod push . oci://ghcr.io/kusionstack --os-arch=linux/amd64 --creds $PACKAGE_TOKEN --latest=true
kusion mod push . oci://ghcr.io/kusionstack --os-arch=windows/amd64 --creds $PACKAGE_TOKEN --latest=true
done