Skip to content

Commit 15d18c4

Browse files
authored
Opprett versjon fil etter release (#131)
1 parent 5dac74e commit 15d18c4

File tree

5 files changed

+49
-2
lines changed

5 files changed

+49
-2
lines changed

Diff for: .github/workflows/publish.yaml

+25-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,28 @@ jobs:
1616
uses: navikt/bidrag-workflow/.github/workflows/maven_publish.yaml@main
1717
with:
1818
version: ${{env.VERSION}}
19-
secrets: inherit
19+
secrets: inherit
20+
21+
commit-version-file:
22+
name: Commit version
23+
runs-on: ubuntu-latest
24+
needs: build-and-release
25+
permissions:
26+
contents: write
27+
steps:
28+
- uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 0
31+
- name: Commit version
32+
env:
33+
versionfile_path: bidrag-inntekt/src/main/resources/versjon.txt
34+
run: |
35+
git config user.name "Automatisk versjon comitter"
36+
git config user.email "[email protected]"
37+
export GIT_COMMIT_HASH=$(git log -n 1 --pretty=format:'%h')
38+
export APP_VERSION=(${{env.VERSION}}_$GIT_COMMIT_HASH)
39+
echo $APP_VERSION > ${{env.versionfile_path}}
40+
echo ⚙️ Opprettet versjonfil med versjon $APP_VERSION
41+
git add ${{env.versionfile_path}}
42+
git commit -m "Oppdater versjonfil til $APP_VERSION"
43+
git push origin HEAD:main

Diff for: .github/workflows/release-draft.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ jobs:
1919
uses: navikt/bidrag-workflow/.github/workflows/maven_release_drafter.yaml@main
2020
secrets: inherit
2121
with:
22-
publish: true
22+
publish: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package no.nav.bidrag.inntekt.util
2+
3+
class VersionProvider {
4+
companion object {
5+
val APP_VERSJON get() = hentFil("/versjon.txt").readText().trim()
6+
}
7+
}
8+
private fun hentFil(filsti: String) = VersionProvider::class.java.getResource(
9+
filsti,
10+
) ?: throw RuntimeException("Fant ingen fil på sti $filsti")

Diff for: bidrag-inntekt/src/main/resources/versjon.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2024.01.23.3123213123_ORIGINAL_COMMIT_HASH
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package no.nav.bidrag.inntekt.util
2+
3+
import io.kotest.matchers.shouldBe
4+
import org.junit.jupiter.api.Test
5+
6+
class VersionProviderTest {
7+
8+
@Test
9+
fun `Skal hente versjon fra fil`() {
10+
VersionProvider.APP_VERSJON shouldBe "2024.01.23.3123213123_ORIGINAL_COMMIT_HASH"
11+
}
12+
}

0 commit comments

Comments
 (0)