Release Unity Package #25
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 | |
| 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 TEST_PROJECT/Packages | |
| mkdir -p TEST_PROJECT/ProjectSettings | |
| echo '{"dependencies": {"com.alexeytaranov.serializereferencedropdown": "file:../../"}}' > TEST_PROJECT/Packages/manifest.json | |
| echo "m_EditorVersion: 2022.3.10f1" > TEST_PROJECT/ProjectSettings/ProjectVersion.txt | |
| - 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: TEST_PROJECT | |
| unityVersion: 2022.3.10f1 | |
| testMode: EditMode | |
| githubToken: ${{ secrets.GITHUB_TOKEN }} | |
| 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 "Skipping release: Last commit was a release." | |
| 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") | |
| else | |
| commits=$(git log $last_tag..HEAD --pretty=format:"%h") | |
| fi | |
| if [ -z "$commits" ]; then | |
| echo "no_new_commits=true" >> $GITHUB_OUTPUT | |
| echo "No new commits since last release." | |
| else | |
| echo "no_new_commits=false" >> $GITHUB_OUTPUT | |
| echo "New commits detected, proceeding with release." | |
| 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 | |
| echo "Version bumped to $new_version" | |
| - 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)") | |
| else | |
| log=$(git log $last_tag..HEAD --pretty=format:"- %s (%h)") | |
| 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** | |
| After merging, a new draft GitHub release will be created automatically. | |
| 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 }} |