diff --git a/.github/workflows/repo.yml b/.github/workflows/repo.yml index 8a37a8e0..0ef92ab8 100644 --- a/.github/workflows/repo.yml +++ b/.github/workflows/repo.yml @@ -78,17 +78,19 @@ jobs: cmd: test publish: - if: ${{ github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'synchronize') }} + if: github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'synchronize') runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # Fetch all history for all branches and tags + - name: Set up Node.js ${{ env.NODE_VERSION }} uses: actions/setup-node@v3 with: node-version: ${{ env.NODE_VERSION }} cache: 'npm' - + - name: Restore node modules from cache uses: actions/cache@v3 with: @@ -96,20 +98,18 @@ jobs: key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }} restore-keys: | ${{ runner.os }}-node- - + - name: Prepare version for publish - id: prep run: | PR_NUMBER=$(echo ${{ github.event.number }}) CURRENT_VERSION=$(node -p "require('./package.json').version") - # Fetch all history for all tags and branches to ensure we're counting accurately - git fetch --prune --unshallow - # Count the number of commits on the current branch and subtract 1 to start the index at 0 + # Ensure we have the full history to accurately count commits + git fetch --prune --unshallow || git fetch --depth=1 origin master:refs/remotes/origin/master + # Count the number of commits on the current branch COMMIT_COUNT=$(($(git log master..HEAD --oneline | wc -l) - 1)) NEW_VERSION="${CURRENT_VERSION}-dev.${PR_NUMBER}.${COMMIT_COUNT}" echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV - + - name: Echo version for testing run: | - echo "Version to publish: $NEW_VERSION" - echo "Adds a commit to test increment" \ No newline at end of file + echo "Version to publish: $NEW_VERSION" \ No newline at end of file