Release Unity Package #40
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: Release Unity Package | |
| on: | |
| push: | |
| branches: [ master ] | |
| workflow_dispatch: | |
| inputs: | |
| bump: | |
| description: "Version bump type (patch/minor/major)" | |
| required: false | |
| default: "patch" | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| checks: write | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| test: | |
| name: Run Unity Tests 🧪 | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| - name: Setup Unity Test Project | |
| run: | | |
| mkdir -p UnityProject/Assets | |
| mkdir -p UnityProject/Packages | |
| mkdir -p UnityProject/ProjectSettings | |
| # Copy package into Packages folder | |
| mkdir -p UnityProject/Packages/com.alexeytaranov.serializereferencedropdown | |
| rsync -a . UnityProject/Packages/com.alexeytaranov.serializereferencedropdown/ \ | |
| --exclude UnityProject \ | |
| --exclude .git \ | |
| --exclude .github | |
| # Register package & dependencies | |
| cat <<EOF > UnityProject/Packages/manifest.json | |
| { | |
| "dependencies": { | |
| "com.alexeytaranov.serializereferencedropdown": "file:com.alexeytaranov.serializereferencedropdown", | |
| "com.unity.test-framework": "1.1.33", | |
| "com.unity.nuget.newtonsoft-json": "3.2.0" | |
| } | |
| } | |
| EOF | |
| # Unity version | |
| echo "m_EditorVersion: 2022.3.10f1" > UnityProject/ProjectSettings/ProjectVersion.txt | |
| - name: Cache Library | |
| uses: actions/cache@v3 | |
| with: | |
| path: UnityProject/Library | |
| key: Library-${{ hashFiles('UnityProject/Packages/manifest.json') }} | |
| restore-keys: | | |
| Library- | |
| - name: Run Unity Tests | |
| uses: game-ci/unity-test-runner@v4 | |
| env: | |
| UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} | |
| UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} | |
| UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} | |
| with: | |
| projectPath: UnityProject | |
| unityVersion: 2022.3.10f1 | |
| testMode: EditMode | |
| githubToken: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Upload Test Results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: Test Results | |
| path: UnityProject/artifacts | |
| release: | |
| needs: test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install jq | |
| run: sudo apt-get install -y jq | |
| - name: Get current version | |
| id: get_version | |
| run: | | |
| version=$(jq -r '.version' package.json) | |
| echo "current_version=$version" >> $GITHUB_OUTPUT | |
| echo "Current version: $version" | |
| - name: Check for new commits since last tag | |
| id: check_commits | |
| run: | | |
| last_commit_msg=$(git log -1 --pretty=%s) | |
| if [[ "$last_commit_msg" == "chore: release"* ]]; then | |
| echo "no_new_commits=true" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| last_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "") | |
| if [ -z "$last_tag" ]; then | |
| commits=$(git log --pretty=format:"%h" -- Editor Runtime Samples~ Tests) | |
| else | |
| commits=$(git log $last_tag..HEAD --pretty=format:"%h" -- Editor Runtime Samples~ Tests) | |
| fi | |
| if [ -z "$commits" ]; then | |
| echo "no_new_commits=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "no_new_commits=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Bump version | |
| if: steps.check_commits.outputs.no_new_commits == 'false' | |
| id: bump_version | |
| run: | | |
| bump="${{ github.event.inputs.bump || 'patch' }}" | |
| version=$(jq -r '.version' package.json) | |
| IFS='.' read -r major minor patch <<< "$version" | |
| case "$bump" in | |
| major) new_version="$((major + 1)).0.0" ;; | |
| minor) new_version="$major.$((minor + 1)).0" ;; | |
| *) new_version="$major.$minor.$((patch + 1))" ;; | |
| esac | |
| jq ".version = \"$new_version\"" package.json > tmp.json && mv tmp.json package.json | |
| echo "new_version=$new_version" >> $GITHUB_OUTPUT | |
| - name: Generate changelog text | |
| if: steps.check_commits.outputs.no_new_commits == 'false' | |
| id: changelog | |
| run: | | |
| last_tag=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") | |
| if [ -z "$last_tag" ]; then | |
| log=$(git log --pretty=format:"- %s (%h)" -- Editor Runtime Samples~ Tests) | |
| else | |
| log=$(git log $last_tag..HEAD --pretty=format:"- %s (%h)" -- Editor Runtime Samples~ Tests) | |
| fi | |
| log=$(echo "$log" | grep -v -E "Merge (pull request|branch)" || true) | |
| echo "$log" > changelog.txt | |
| echo "log<<EOF" >> $GITHUB_OUTPUT | |
| echo "$log" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Update CHANGELOG.md | |
| if: steps.check_commits.outputs.no_new_commits == 'false' | |
| run: | | |
| VERSION=${{ steps.bump_version.outputs.new_version }} | |
| DATE=$(date +'%Y-%m-%d') | |
| echo "## v$VERSION - $DATE" > new_changelog.md | |
| cat changelog.txt >> new_changelog.md | |
| echo "" >> new_changelog.md | |
| if [ -f CHANGELOG.md ]; then | |
| cat CHANGELOG.md >> new_changelog.md | |
| fi | |
| mv new_changelog.md CHANGELOG.md | |
| - name: Create PR with version bump | |
| if: steps.check_commits.outputs.no_new_commits == 'false' | |
| uses: peter-evans/create-pull-request@v6 | |
| with: | |
| commit-message: "chore: release v${{ steps.bump_version.outputs.new_version }}" | |
| branch: "release/v${{ steps.bump_version.outputs.new_version }}" | |
| title: "Release v${{ steps.bump_version.outputs.new_version }}" | |
| body: | | |
| This PR updates: | |
| - **package.json** | |
| - **CHANGELOG.md** | |
| labels: release | |
| add-paths: | | |
| package.json | |
| CHANGELOG.md | |
| - name: Create draft GitHub release | |
| if: steps.check_commits.outputs.no_new_commits == 'false' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ steps.bump_version.outputs.new_version }} | |
| name: Release ${{ steps.bump_version.outputs.new_version }} | |
| body: | | |
| 🧩 Unity package **com.alexeytaranov.serializereferencedropdown** | |
| Version: ${{ steps.bump_version.outputs.new_version }} | |
| ### Changelog | |
| ${{ steps.changelog.outputs.log }} | |
| draft: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |