1+ name : Auto-Publish on Visibility Change
2+
3+ on :
4+ schedule :
5+ # Check every hour for visibility changes
6+ - cron : ' 0 * * * *'
7+ workflow_dispatch :
8+ inputs :
9+ sdk_name :
10+ description : ' SDK name to check'
11+ required : true
12+ default : ' satox-sdk'
13+ platforms :
14+ description : ' Platforms to publish to'
15+ required : true
16+ default : ' dockerhub,npm,pypi,maven,nuget,crates'
17+
18+ jobs :
19+ check-visibility-and-publish :
20+ name : Check Visibility and Auto-Publish
21+ runs-on : ubuntu-latest
22+
23+ strategy :
24+ matrix :
25+ sdk : [satox-sdk, satox-mobile-sdk, satox-game-sdk]
26+
27+ steps :
28+ - name : Checkout code
29+ uses : actions/checkout@v4
30+
31+ - name : Setup environment
32+ run : |
33+ echo "Setting up publishing environment..."
34+ chmod +x scripts/release-management.sh
35+
36+ - name : Check repository visibility
37+ id : check-visibility
38+ run : |
39+ echo "Checking visibility for ${{ matrix.sdk }}..."
40+ visibility=$(./scripts/release-management.sh check-visibility ${{ matrix.sdk }} | grep -o 'public\|private')
41+ echo "visibility=$visibility" >> $GITHUB_OUTPUT
42+
43+ # Store current visibility
44+ echo "$visibility" > ".visibility_${{ matrix.sdk }}"
45+
46+ # Check if visibility changed from private to public
47+ if [[ -f ".visibility_${{ matrix.sdk }}.last" ]]; then
48+ previous_visibility=$(cat ".visibility_${{ matrix.sdk }}.last")
49+ if [[ "$previous_visibility" == "private" && "$visibility" == "public" ]]; then
50+ echo "visibility_changed=true" >> $GITHUB_OUTPUT
51+ echo "🎉 Repository ${{ matrix.sdk }} changed from private to public!"
52+ else
53+ echo "visibility_changed=false" >> $GITHUB_OUTPUT
54+ fi
55+ else
56+ echo "visibility_changed=false" >> $GITHUB_OUTPUT
57+ fi
58+
59+ # Update last visibility
60+ cp ".visibility_${{ matrix.sdk }}" ".visibility_${{ matrix.sdk }}.last"
61+
62+ - name : Get latest version
63+ id : get-version
64+ if : steps.check-visibility.outputs.visibility_changed == 'true'
65+ run : |
66+ echo "Getting latest version for ${{ matrix.sdk }}..."
67+ latest_version=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
68+ "https://api.github.com/repos/satoverse/${{ matrix.sdk }}/releases/latest" | \
69+ jq -r '.tag_name // "v1.0.0"' | sed 's/^v//')
70+ echo "version=$latest_version" >> $GITHUB_OUTPUT
71+ echo "Latest version: $latest_version"
72+
73+ - name : Setup Docker
74+ if : steps.check-visibility.outputs.visibility_changed == 'true'
75+ uses : docker/setup-buildx-action@v3
76+
77+ - name : Login to Docker Hub
78+ if : steps.check-visibility.outputs.visibility_changed == 'true'
79+ uses : docker/login-action@v3
80+ with :
81+ username : ${{ secrets.DOCKERHUB_USERNAME }}
82+ password : ${{ secrets.DOCKERHUB_TOKEN }}
83+
84+ - name : Publish to Docker Hub
85+ if : steps.check-visibility.outputs.visibility_changed == 'true'
86+ run : |
87+ echo "Publishing ${{ matrix.sdk }} v${{ steps.get-version.outputs.version }} to Docker Hub..."
88+ ./scripts/release-management.sh release ${{ matrix.sdk }} ${{ steps.get-version.outputs.version }} "Auto-published on visibility change" dockerhub
89+
90+ - name : Setup Node.js
91+ if : ${{ hashFiles('package-lock.json', 'yarn.lock', 'npm-shrinkwrap.json') != '' }}
92+ uses : actions/setup-node@v4
93+ with :
94+ node-version : ' 18'
95+ registry-url : ' https://registry.npmjs.org'
96+
97+ - name : Cache node_modules
98+ uses : actions/cache@v4
99+ with :
100+ path : |
101+ node_modules
102+ **/node_modules
103+ key : ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock', '**/package-lock.json') }}
104+ restore-keys : |
105+ ${{ runner.os }}-node-
106+
107+ - name : Publish to npm
108+ if : steps.check-visibility.outputs.visibility_changed == 'true'
109+ run : |
110+ echo "Publishing ${{ matrix.sdk }} v${{ steps.get-version.outputs.version }} to npm..."
111+ ./scripts/release-management.sh release ${{ matrix.sdk }} ${{ steps.get-version.outputs.version }} "Auto-published on visibility change" npm
112+ env :
113+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
114+
115+ - name : Setup Python
116+ if : steps.check-visibility.outputs.visibility_changed == 'true'
117+ uses : actions/setup-python@v4
118+ with :
119+ python-version : ' 3.9'
120+
121+ - name : Cache pip
122+ uses : actions/cache@v4
123+ with :
124+ path : ~/.cache/pip
125+ key : ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
126+ restore-keys : |
127+ ${{ runner.os }}-pip-
128+
129+ - name : Publish to PyPI
130+ if : steps.check-visibility.outputs.visibility_changed == 'true'
131+ run : |
132+ echo "Publishing ${{ matrix.sdk }} v${{ steps.get-version.outputs.version }} to PyPI..."
133+ ./scripts/release-management.sh release ${{ matrix.sdk }} ${{ steps.get-version.outputs.version }} "Auto-published on visibility change" pypi
134+ env :
135+ PYPI_TOKEN : ${{ secrets.PYPI_TOKEN }}
136+
137+ - name : Setup Java
138+ if : steps.check-visibility.outputs.visibility_changed == 'true'
139+ uses : actions/setup-java@v4
140+ with :
141+ distribution : ' temurin'
142+ java-version : ' 11'
143+
144+ - name : Cache Maven packages
145+ uses : actions/cache@v4
146+ with :
147+ path : ~/.m2/repository
148+ key : ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
149+ restore-keys : |
150+ ${{ runner.os }}-maven-
151+
152+ - name : Publish to Maven Central
153+ if : steps.check-visibility.outputs.visibility_changed == 'true'
154+ run : |
155+ echo "Publishing ${{ matrix.sdk }} v${{ steps.get-version.outputs.version }} to Maven Central..."
156+ ./scripts/release-management.sh release ${{ matrix.sdk }} ${{ steps.get-version.outputs.version }} "Auto-published on visibility change" maven
157+ env :
158+ MAVEN_USERNAME : ${{ secrets.MAVEN_USERNAME }}
159+ MAVEN_PASSWORD : ${{ secrets.MAVEN_PASSWORD }}
160+
161+ - name : Setup .NET
162+ if : steps.check-visibility.outputs.visibility_changed == 'true'
163+ uses : actions/setup-dotnet@v4
164+ with :
165+ dotnet-version : ' 6.0.x'
166+
167+ - name : Publish to NuGet
168+ if : steps.check-visibility.outputs.visibility_changed == 'true'
169+ run : |
170+ echo "Publishing ${{ matrix.sdk }} v${{ steps.get-version.outputs.version }} to NuGet..."
171+ ./scripts/release-management.sh release ${{ matrix.sdk }} ${{ steps.get-version.outputs.version }} "Auto-published on visibility change" nuget
172+ env :
173+ NUGET_API_KEY : ${{ secrets.NUGET_API_KEY }}
174+
175+ - name : Setup Rust
176+ if : steps.check-visibility.outputs.visibility_changed == 'true'
177+ uses : actions-rs/toolchain@v1
178+ with :
179+ toolchain : stable
180+
181+ - name : Cache cargo registry
182+ uses : actions/cache@v4
183+ with :
184+ path : ~/.cargo/registry
185+ key : ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
186+ restore-keys : |
187+ ${{ runner.os }}-cargo-registry-
188+
189+ - name : Cache cargo build
190+ uses : actions/cache@v4
191+ with :
192+ path : target
193+ key : ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
194+ restore-keys : |
195+ ${{ runner.os }}-cargo-build-
196+
197+ - name : Cache Go modules
198+ uses : actions/cache@v4
199+ with :
200+ path : ~/go/pkg/mod
201+ key : ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
202+ restore-keys : |
203+ ${{ runner.os }}-go-
204+
205+ - name : Publish to Crates.io
206+ if : steps.check-visibility.outputs.visibility_changed == 'true'
207+ run : |
208+ echo "Publishing ${{ matrix.sdk }} v${{ steps.get-version.outputs.version }} to Crates.io..."
209+ ./scripts/release-management.sh release ${{ matrix.sdk }} ${{ steps.get-version.outputs.version }} "Auto-published on visibility change" crates
210+ env :
211+ CRATES_TOKEN : ${{ secrets.CRATES_TOKEN }}
212+
213+ - name : Create Homebrew formula
214+ if : steps.check-visibility.outputs.visibility_changed == 'true'
215+ run : |
216+ echo "Creating Homebrew formula for ${{ matrix.sdk }} v${{ steps.get-version.outputs.version }}..."
217+ ./scripts/release-management.sh release ${{ matrix.sdk }} ${{ steps.get-version.outputs.version }} "Auto-published on visibility change" homebrew
218+
219+ - name : Notify success
220+ if : steps.check-visibility.outputs.visibility_changed == 'true'
221+ run : |
222+ echo "🎉 Successfully auto-published ${{ matrix.sdk }} v${{ steps.get-version.outputs.version }} to all platforms!"
223+ echo "Platforms published to:"
224+ echo "- Docker Hub"
225+ echo "- npm"
226+ echo "- PyPI"
227+ echo "- Maven Central"
228+ echo "- NuGet"
229+ echo "- Crates.io"
230+ echo "- Homebrew (formula created)"
231+
232+ - name : Notify no change
233+ if : steps.check-visibility.outputs.visibility_changed == 'false'
234+ run : |
235+ echo "ℹ️ No visibility change detected for ${{ matrix.sdk }}"
236+ echo "Current visibility: ${{ steps.check-visibility.outputs.visibility }}"
0 commit comments