Push Release #6
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 UPM Package | |
| on: | |
| push: | |
| tags: | |
| - "v*.*.*" # Trigger on semantic version tags | |
| jobs: | |
| update-version: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Step 1: Check out the repository | |
| - name: Check out code | |
| uses: actions/checkout@v3 | |
| # Step 2: Extract version tag and update package.json | |
| - name: Update package.json version | |
| run: | | |
| echo "GitHub Ref: $GITHUB_REF" | |
| TAG=$(echo $GITHUB_REF | sed 's|refs/tags/||') | |
| echo "Extracted TAG: $TAG" | |
| if [ -f package.json ]; then | |
| sed -i "s/\"version\": \".*\"/\"version\": \"$TAG\"/" package.json | |
| cat package.json | |
| # Switch to the branch before committing | |
| DEFAULT_BRANCH=$(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5) | |
| echo "Default branch: $DEFAULT_BRANCH" | |
| git checkout $DEFAULT_BRANCH | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add package.json | |
| git commit -m "Update package version to $TAG" | |
| git push origin $DEFAULT_BRANCH | |
| else | |
| echo "Error: package.json not found at the root" | |
| exit 1 | |
| fi | |
| shell: bash | |
| # Step 3: Optional - Create a GitHub release | |
| - name: Create GitHub Release | |
| uses: actions/create-release@v1 | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| release_name: "Release ${{ github.ref_name }}" | |
| body: "Automatic release of Unity package version ${{ github.ref_name }}." | |
| draft: false | |
| prerelease: false |