-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.yml
More file actions
83 lines (77 loc) · 3.38 KB
/
action.yml
File metadata and controls
83 lines (77 loc) · 3.38 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
---
name: Get build number
description: GitHub Action to get the build number for a repository
outputs:
BUILD_NUMBER:
description: The build number, incremented or reused if already cached
value: ${{ steps.export.outputs.BUILD_NUMBER }}
inputs:
host-actions-root:
description: Path to the actions folder on the host (used when called from another local action)
default: ''
runs:
using: composite
steps:
- name: Set local action paths
id: set-path
shell: bash
run: |
echo "::group::Fix for using local actions"
echo "GITHUB_ACTION_PATH=$GITHUB_ACTION_PATH"
echo "github.action_path=${{ github.action_path }}"
ACTION_PATH_GET_BUILD_NUMBER="${{ github.action_path }}"
host_actions_root="${{ inputs.host-actions-root }}"
if [ -z "$host_actions_root" ]; then
host_actions_root="$(dirname "$ACTION_PATH_GET_BUILD_NUMBER")"
else
ACTION_PATH_GET_BUILD_NUMBER="$host_actions_root/get-build-number"
fi
echo "ACTION_PATH_GET_BUILD_NUMBER=$ACTION_PATH_GET_BUILD_NUMBER"
echo "ACTION_PATH_GET_BUILD_NUMBER=$ACTION_PATH_GET_BUILD_NUMBER" >> "$GITHUB_ENV"
echo "::endgroup::"
# Reuse build number from environment if provided (e.g. from a parent workflow)
- name: Save build number from environment to file
id: from-env
if: env.BUILD_NUMBER != ''
shell: bash
run: |
echo "BUILD_NUMBER ${BUILD_NUMBER} provided from environment, skipping both increment and save to cache."
echo "${BUILD_NUMBER}" > build_number.txt
echo "skip=true" >> $GITHUB_OUTPUT
# Reuse current build number in case of rerun
- name: Get cached build number
if: steps.from-env.outputs.skip != 'true'
uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
id: current-build-number
with:
path: build_number.txt
key: build-number-${{ github.run_id }}
enableCrossOsArchive: true
# Otherwise, increment the build number
- uses: SonarSource/vault-action-wrapper@545e7cfbb5528e7009a1edcc83e073898d292627 # 3.2.0
id: secrets
if: steps.from-env.outputs.skip != 'true' && steps.current-build-number.outputs.cache-hit != 'true'
with:
secrets: development/github/token/{REPO_OWNER_NAME_DASH}-build-number token | github_token;
- name: Get new build number
if: steps.from-env.outputs.skip != 'true' && steps.current-build-number.outputs.cache-hit != 'true'
shell: bash
env:
GITHUB_TOKEN: ${{ steps.current-build-number.outputs.cache-hit != 'true' &&
steps.secrets.outputs.vault && fromJSON(steps.secrets.outputs.vault).github_token || '' }}
run: ${ACTION_PATH_GET_BUILD_NUMBER}/get_build_number.sh
- name: Export build number
id: export
shell: bash
run: |
BUILD_NUMBER=$(cat build_number.txt)
echo "BUILD_NUMBER: ${BUILD_NUMBER}"
echo "BUILD_NUMBER=${BUILD_NUMBER}" >> "$GITHUB_ENV"
echo "BUILD_NUMBER=${BUILD_NUMBER}" >> "$GITHUB_OUTPUT"
- name: Save build number to cache
uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
if: steps.from-env.outputs.skip != 'true' && steps.current-build-number.outputs.cache-hit != 'true'
with:
path: build_number.txt
key: build-number-${{ github.run_id }}
enableCrossOsArchive: true