-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshared-increase-version-number.yaml
More file actions
99 lines (91 loc) · 4.73 KB
/
shared-increase-version-number.yaml
File metadata and controls
99 lines (91 loc) · 4.73 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Shared Increase Version Number
on:
workflow_call:
inputs:
release_type:
description: The type of version number to return. Must be one of [Snapshot, Patch, Minor or Major]
required: true
type: string
version_number_input:
description: If set, the version number will not be incremented and the given number will be used.
default: ''
type: string
working_dir:
description: The path to the directory for which the version should be determined.
type: string
default: '.'
merge_environment:
description: GitHub Environment to use for accessing the merge token. Leave empty to use the default GITHUB_TOKEN.
type: string
default: ''
outputs:
new_version:
description: The new version number to publish for the docker repo
value: ${{ jobs.incrementVersionNumber.outputs.new_version }}
image_tag:
description: The image tag used to extract metadata for Docker
value: ${{ jobs.incrementVersionNumber.outputs.image_tag }}
git_tag_or_hash:
description: The git tag or hash (for snapshots) containing the updated version.
value: ${{ jobs.incrementVersionNumber.outputs.git_tag_or_hash }}
jobs:
incrementVersionNumber:
runs-on: ubuntu-latest
environment: ${{ inputs.merge_environment }}
outputs:
new_version: ${{ steps.version.outputs.new_version }}
image_tag: ${{ steps.updatePackageJson.outputs.image_tag }}
git_tag_or_hash: ${{ steps.commit-and-tag.outcome == 'success' && steps.commit-and-tag.outputs.git_tag_or_hash || steps.commit-without-tag.outputs.git_tag_or_hash }}
steps:
- name: Setup
id: setup
uses: IABTechLab/uid2-shared-actions/actions/shared_publish_setup@v2
with:
release_type: ${{ inputs.release_type }}
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Set version number
id: version
uses: IABTechLab/uid2-shared-actions/actions/version_number@v2
with:
type: ${{ inputs.release_type }}
version_number: ${{ inputs.version_number_input }}
branch_name: ${{ github.ref }}
working_dir: ${{ inputs.working_dir }}
- name: Update ${{ inputs.working_dir }}/package.json
id: updatePackageJson
run: |
current_version=$(jq -r '.version')
new_version=${{ steps.version.outputs.new_version }}
jq --arg v "$new_version" ".version = \$v" "${{ inputs.working_dir }}/package.json" > tmp.json && mv tmp.json "${{ inputs.working_dir }}/package.json"
echo "Version number updated from $current_version to $new_version"
echo "image_tag=${{ steps.version.outputs.new_version }}" >> $GITHUB_OUTPUT
- name: Update ${{ inputs.working_dir }}/package-lock.json
id: updatePackageLockJson
run: |
npm install --package-lock-only
- name: Commit ${{ inputs.working_dir }}/package.json, ${{ inputs.working_dir }}/package-lock.json and ${{ inputs.working_dir }}/version.json
if: ${{ inputs.version_number_input == '' && steps.setup.outputs.IS_RELEASE != 'true' }}
id: commit-without-tag
uses: IABTechLab/uid2-shared-actions/actions/commit_pr_and_merge@v3
with:
add: '${{ inputs.working_dir }}/package.json ${{ inputs.working_dir }}/package-lock.json ${{ inputs.working_dir }}/version.json'
message: 'Released ${{ inputs.release_type }} version: ${{ steps.version.outputs.new_version }}'
github_token: ${{ inputs.merge_environment != '' && secrets.GH_MERGE_TOKEN || '' }}
- name: Commit ${{ inputs.working_dir }}/package.json, ${{ inputs.working_dir }}/package-lock.json, ${{ inputs.working_dir }}/version.json and set tag
if: ${{ inputs.version_number_input == '' && steps.setup.outputs.IS_RELEASE == 'true' }}
id: commit-and-tag
uses: IABTechLab/uid2-shared-actions/actions/commit_pr_and_merge@v3
with:
add: '${{ inputs.working_dir }}/package.json ${{ inputs.working_dir }}/package-lock.json ${{ inputs.working_dir }}/version.json'
message: 'Released ${{ inputs.release_type }} version: ${{ steps.version.outputs.new_version }}'
tag: v${{ steps.version.outputs.new_version }}
github_token: ${{ inputs.merge_environment != '' && secrets.GH_MERGE_TOKEN || '' }}
- name: Print outputs
uses: actions/github-script@v7
with:
script: |
console.log('Result', '${{ steps.commit-and-tag.outcome }}');
console.log('Commit and tag', '${{ steps.commit-and-tag.outputs.git_tag_or_hash }}');
console.log('No tag', '${{ steps.commit-without-tag.outputs.git_tag_or_hash }}');