Repository navigation
Mirror official uGUI from Unity 6000.0.58f1 ❤️ #43
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish to Registry | |
| on: | |
| push: | |
| tags: ["v*"] | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| - name: Extract version and determine dist-tag | |
| id: meta | |
| run: | | |
| VERSION="${GITHUB_REF_NAME#v}" | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| if [[ "$VERSION" == *-* ]]; then | |
| PRERELEASE="${VERSION#*-}" | |
| TAG="${PRERELEASE%%.*}" | |
| echo "tag=$TAG" >> "$GITHUB_OUTPUT" | |
| echo "prerelease=true" >> "$GITHUB_OUTPUT" | |
| echo "Detected pre-release: tag=$TAG" | |
| else | |
| echo "prerelease=false" >> "$GITHUB_OUTPUT" | |
| CURRENT=$(curl -sf -H "Authorization: Bearer ${{ secrets.REGISTRY_TOKEN }}" \ | |
| https://registry.lightside.media/com.unity.ugui 2>/dev/null \ | |
| | node -e "try{const d=JSON.parse(require('fs').readFileSync(0,'utf8'));console.log(d['dist-tags']?.latest||'')}catch{}" 2>/dev/null) | |
| if [ -n "$CURRENT" ]; then | |
| OLDER=$(node -e " | |
| const part = (v, i) => Number(v.split('-')[0].split('.')[i] || 0); | |
| const cmp = (a, b) => [0, 1, 2].reduce((r, i) => r || part(a, i) - part(b, i), 0); | |
| console.log(cmp(process.argv[1], process.argv[2]) < 0 ? '1' : ''); | |
| " "$VERSION" "$CURRENT") | |
| if [ -n "$OLDER" ]; then | |
| TAG="v${VERSION%.*}" | |
| echo "tag=$TAG" >> "$GITHUB_OUTPUT" | |
| echo "Older release line: tag=$TAG (latest is $CURRENT)" | |
| else | |
| TAG="latest" | |
| echo "tag=$TAG" >> "$GITHUB_OUTPUT" | |
| echo "New stable release: tag=latest" | |
| fi | |
| else | |
| TAG="latest" | |
| echo "tag=$TAG" >> "$GITHUB_OUTPUT" | |
| echo "First publish: tag=latest" | |
| fi | |
| fi | |
| - name: Set version in package.json | |
| run: | | |
| node -e " | |
| const fs = require('fs'); | |
| const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); | |
| if (pkg.version === '${{ steps.meta.outputs.version }}') process.exit(0); | |
| pkg.version = '${{ steps.meta.outputs.version }}'; | |
| fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n'); | |
| " | |
| - name: Pack tarball | |
| run: npm pack | |
| - name: Upload tarball to R2 | |
| run: | | |
| npx wrangler r2 object put "registry-packages/com.unity.ugui-${{ steps.meta.outputs.version }}.tgz" \ | |
| --file="com.unity.ugui-${{ steps.meta.outputs.version }}.tgz" \ | |
| --content-type="application/octet-stream" \ | |
| --remote | |
| env: | |
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| - name: Register metadata | |
| run: | | |
| MANIFEST=$(node -e " | |
| const fs = require('fs'); | |
| const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); | |
| pkg.dist = { tarball: 'https://registry.lightside.media/com.unity.ugui/-/com.unity.ugui-${{ steps.meta.outputs.version }}.tgz' }; | |
| console.log(JSON.stringify(pkg)); | |
| ") | |
| curl -svf -X POST "https://registry.lightside.media/-/admin/publish" \ | |
| -H "Authorization: Bearer ${{ secrets.REGISTRY_TOKEN }}" \ | |
| -H "Content-Type: application/json" \ | |
| -d "{ | |
| \"name\": \"com.unity.ugui\", | |
| \"version\": \"${{ steps.meta.outputs.version }}\", | |
| \"tag\": \"${{ steps.meta.outputs.tag }}\", | |
| \"manifest\": $MANIFEST | |
| }" | |
| echo "" | |
| echo "Published com.unity.ugui@${{ steps.meta.outputs.version }} with tag=${{ steps.meta.outputs.tag }}" | |
| - name: Finalize release commit | |
| run: | | |
| git fetch origin '+refs/heads/*:refs/remotes/origin/*' --no-tags --quiet | |
| BRANCH=$(git branch -r --contains HEAD --sort=-committerdate \ | |
| | grep -v HEAD | sed 's|^ *origin/||' | head -1) | |
| if [ -z "$BRANCH" ]; then | |
| echo "Could not determine source branch for tag $GITHUB_REF_NAME" | |
| exit 1 | |
| fi | |
| echo "Detected branch: $BRANCH" | |
| git add package.json | |
| if git diff --cached --quiet; then | |
| echo "Nothing to amend — commit already up to date" | |
| exit 0 | |
| fi | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git commit --amend --no-edit | |
| git tag -f "$GITHUB_REF_NAME" | |
| git push --force origin "HEAD:refs/heads/$BRANCH" | |
| git push --force origin "$GITHUB_REF_NAME" |