forked from moby/moby
/
action.yml
51 lines (43 loc) · 1.43 KB
/
action.yml
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
name: Retrieves project information
description: Retrieves project information
author: nosamad
inputs:
version:
description: Version string
default: ''
required: false
outputs:
version:
description: Effective project version string
value: ${{ steps.setup-project-info.outputs.version }}
buildtime:
description: Build time string
value: ${{ steps.setup-project-info.outputs.buildtime }}
runs:
using: composite
steps:
- name: Check environment
run: |
command -V date
command -V git
command -V sed
command -V bash
shell: sh
- name: Set up Project information
id: setup-project-info
env:
VERSION: ${{ inputs.version }}
run: |
export TZ=UTC
SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(git log -1 --pretty='%ct')}"
echo "SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH}" >> "${GITHUB_ENV}"
static_version="$VERSION"
if [[ -z "${static_version}" ]] || [[ "${static_version}" == *-dev ]]; then
git_date="$(date --utc --date "@${SOURCE_DATE_EPOCH}" +'%Y%m%d%H%M%S')"
git_commit="$(git log -1 --pretty='%h')"
static_version="0.0.0-${git_date}-${git_commit}"
fi
echo "::set-output name=version::${static_version}"
buildtime="$(date -u -d "@${SOURCE_DATE_EPOCH}" --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/')"
echo "::set-output name=buildtime::${buildtime}"
shell: bash