Skip to content
This repository was archived by the owner on Oct 26, 2022. It is now read-only.

Commit dcfa6c2

Browse files
author
Rohith Reddy
committed
resolve #6 with a better version change detection
1 parent 122ae60 commit dcfa6c2

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ jobs:
1717
steps:
1818
# Checkout
1919
- uses: actions/checkout@v2
20-
with:
21-
fetch-depth: 2 # This must be >= 2 to compare commits
2220

23-
# Optional step, add only for a specific dotnet version that doesn't come with ubuntu-latest
24-
# For a list of software that comes pre-installed with ubuntu-latest visit bit.ly/2synnZl
21+
# Optional step, add only for a specific dotnet version that doesn't come with ubuntu-latest / windows-latest
22+
# Visit bit.ly/2synnZl for a list of software that comes pre-installed with ubuntu-latest / windows-latest
2523
# - name: Setup dotnet
2624
# uses: actions/setup-dotnet@v1
2725
# with:
@@ -36,7 +34,8 @@ jobs:
3634
# nuget_key: ${{secrets.NUGET_API_KEY}} # nuget.org API key
3735
```
3836

39-
Project version updates are monitored on every push / PR merge to master & a new tag is created to denote the updated version. If a `nuget_key` is passed then the project gets built, packed & published to nuget.org
37+
- Project version updates are monitored on every push / PR merge to master & a new tag is created to denote the updated version
38+
- If a `nuget_key` is present then the project gets built, packed & published to nuget.org
4039

4140
## Inputs
4241
All these inputs are optional

index.js

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,40 @@ const resolve = require("path").resolve,
33
{ readdirSync, readFileSync } = require("fs")
44

55
function run() {
6-
// check fetch-depth
7-
const commitCount = parseInt(runCap("git rev-list --count HEAD"))
8-
if (commitCount < 2) {
9-
failed("😤 git commit history must be >= 2")
10-
return
11-
}
12-
136
// find project
147
const repoDir = process.env.GITHUB_WORKSPACE,
158
projDir = resolve(repoDir, process.env.INPUT_PROJECT_DIR),
169
projFiles = readdirSync(projDir).filter(f => f.endsWith(".csproj") || f.endsWith(".fsproj"))
17-
10+
1811
if (projFiles.length === 0) {
1912
failed("😭 project not found")
2013
return
2114
}
2215

23-
// check for version changes
16+
// check for new version
2417
const projName = projFiles[0],
25-
projPath = resolve(projDir, projName).replace("\\", "\\\\"),
18+
projPath = resolve(projDir, projName),
2619
versionRegex = /<Version>(.*)<\/Version>/,
27-
gitDiff = runCap(`git diff -U0 HEAD^ -- ${projPath}`),
28-
isVersionChanged = versionRegex.test(gitDiff)
20+
projDetails = readFileSync(projPath, { encoding: "utf-8" }),
21+
isVersionPresent = versionRegex.test(projDetails)
2922

30-
if (!isVersionChanged) {
31-
console.log(`🥱 no version change for ${projName}`)
23+
if (!isVersionPresent) {
24+
console.log(`##[warning]😢 skipping due to no version`)
3225
return
3326
}
3427

35-
console.log(`👍 found a new version for ${projName}`)
36-
37-
// create tag
38-
const projContents = readFileSync(projPath, { encoding: "utf-8" }),
39-
newVersion = versionRegex.exec(projContents)[1],
28+
const currentVersion = versionRegex.exec(projDetails)[1],
4029
tagFormat = process.env.INPUT_TAG_FORMAT,
41-
tag = tagFormat.replace("*", newVersion),
30+
tag = tagFormat.replace("*", currentVersion),
4231
istagPresent = runCap(`git ls-remote --tags origin ${tag}`).indexOf(tag) >= 0
4332

4433
if (istagPresent) {
45-
console.log(`##[warning]😢 tag ${newVersion} already exists`)
34+
console.log(`##[warning]😢 tag ${currentVersion} already exists`)
4635
return
4736
}
4837

38+
console.log(`👍 found a new version (${currentVersion}) of ${projName}`)
39+
4940
runProc(`git tag ${tag}`)
5041
runProc(`git push origin ${tag}`)
5142

0 commit comments

Comments
 (0)