-
-
Notifications
You must be signed in to change notification settings - Fork 7
84 lines (74 loc) · 2.63 KB
/
git-version.yml
File metadata and controls
84 lines (74 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: Git Version
on:
workflow_call:
inputs:
version:
description: 'The version of GitVersion to use'
required: false
type: string
default: '0.7.3'
project_path:
description: 'The path to the project to build. Used for Git Version.'
required: false
type: string
default: '.'
submodules:
description: 'Whether to checkout submodules: `true` to checkout submodules or `recursive` to recursively checkout submodules.'
required: false
type: string
default: 'false'
outputs:
build_number:
value: ${{ jobs.git-version.outputs.build_number }}
permissions:
contents: read
jobs:
git-version:
name: Git Version
runs-on: ubuntu-latest
outputs:
build_number: ${{ steps.git-version.outputs.GIT_VERSION }}
steps:
- name: Checkout Repository
id: checkout
uses: actions/checkout@v6
with:
submodules: ${{ inputs.submodules }}
fetch-depth: 1000
fetch-tags: true
- name: Work around actions/checkout#2041
id: checkout-tags
# language=bash
run: git fetch --tags
- name: Setup Java 17
id: setup-java
# https://github.com/actions/runner-images/blob/main/images/linux/Ubuntu2204-Readme.md#java
# We use this instead of the recommended `actions/setup-java` action because this is faster
# language=bash
run: echo "JAVA_HOME=$(echo $JAVA_HOME_17_X64)" >> "$GITHUB_ENV"
- name: Cache Git Version
id: git-version-cache
uses: actions/cache@v5
with:
key: gitversion-${{ inputs.version }}
path: gitversion.jar
- name: Download Git Version
id: git-version-download
if: steps.git-version-cache.outputs.cache-hit != 'true'
shell: bash
# language=bash
run: wget 'https://maven.minecraftforge.net/net/minecraftforge/gitversion/${{ inputs.version }}/gitversion-${{ inputs.version }}-fatjar.jar' -O gitversion.jar
- name: Run Git Version
id: git-version
shell: bash
# language=bash
run: |-
# Get the version number from Git Version
GIT_VERSION=$(java -jar gitversion.jar --project-dir ${{ inputs.project_path }})
# If the command failed or there is no version number, stop now
if [[ $? -ne 0 ]] || [[ -z $GIT_VERSION ]]; then
echo "Failed to get version number! Refusing to build."
exit 1
fi
echo "Version: $GIT_VERSION"
echo "GIT_VERSION=$GIT_VERSION" >> $GITHUB_OUTPUT