@@ -78,38 +78,38 @@ jobs:
78
78
cmd : test
79
79
80
80
publish :
81
- if : ${{ github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'synchronize') }}
81
+ if : github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'synchronize')
82
82
runs-on : ubuntu-latest
83
83
steps :
84
- - uses : actions/checkout@v2
85
-
84
+ - uses : actions/checkout@v3
85
+ with :
86
+ fetch-depth : 0 # Fetch all history for all branches and tags
87
+
86
88
- name : Set up Node.js ${{ env.NODE_VERSION }}
87
89
uses : actions/setup-node@v3
88
90
with :
89
91
node-version : ${{ env.NODE_VERSION }}
90
92
cache : ' npm'
91
-
93
+
92
94
- name : Restore node modules from cache
93
95
uses : actions/cache@v3
94
96
with :
95
97
path : node_modules
96
98
key : ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
97
99
restore-keys : |
98
100
${{ runner.os }}-node-
99
-
101
+
100
102
- name : Prepare version for publish
101
- id : prep
102
103
run : |
103
104
PR_NUMBER=$(echo ${{ github.event.number }})
104
105
CURRENT_VERSION=$(node -p "require('./package.json').version")
105
- # Fetch all history for all tags and branches to ensure we're counting accurately
106
- git fetch --prune --unshallow
107
- # Count the number of commits on the current branch and subtract 1 to start the index at 0
106
+ # Ensure we have the full history to accurately count commits
107
+ git fetch --prune --unshallow || git fetch --depth=1 origin master:refs/remotes/origin/master
108
+ # Count the number of commits on the current branch
108
109
COMMIT_COUNT=$(($(git log master..HEAD --oneline | wc -l) - 1))
109
110
NEW_VERSION="${CURRENT_VERSION}-dev.${PR_NUMBER}.${COMMIT_COUNT}"
110
111
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
111
-
112
+
112
113
- name : Echo version for testing
113
114
run : |
114
- echo "Version to publish: $NEW_VERSION"
115
- echo "Adds a commit to test increment"
115
+ echo "Version to publish: $NEW_VERSION"
0 commit comments