-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (117 loc) · 5.62 KB
/
Copy pathMetadata.yml
File metadata and controls
132 lines (117 loc) · 5.62 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Display Name of the workflow
name: Calculate - Metadata
# Event listeners for when the job should start execution
on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Allow this workflow to be called from another workflow
workflow_call:
inputs:
correlationId:
description: 'Correlates the origin job with the child instance since process start does not return an ID.'
type: string
required: false
isRelease:
description: 'Indicates that the calling workflow was triggered by a release.'
type: boolean
required: false
default: false
isPrerelease:
description: 'Indicates that the calling release is a prerelease.'
type: boolean
required: false
default: false
outputs:
channel:
description: 'The channel that the build should be published to.'
value: ${{ jobs.Deploy-Metadata.outputs.channel }}
environment:
description: 'The GitHub Environment that the build should use.'
value: ${{ jobs.Deploy-Metadata.outputs.environment }}
shortSha:
description: 'The first 7 characters of the SHA hash that represents the current commit that the build is operating off of.'
value: ${{ jobs.Deploy-Metadata.outputs.shortSha }}
version:
description: 'The version of the project that is being built.'
value: ${{ jobs.Deploy-Metadata.outputs.version }}
semver:
description: 'The semantic version of the project that is being built.'
value: ${{ jobs.Deploy-Metadata.outputs.semver }}
nodeRuntime:
description: 'The Node.JS runtime version required by the project.'
value: ${{ jobs.Deploy-Metadata.outputs.nodeRuntime }}
# Define each session of execution that should be executed
jobs:
# Calculates the tag and channel metadata based on the event that triggered the workflow, and making that data available to downstream jobs through outputs.
Deploy-Metadata:
# Human friendly display name for the job
name: Calculate - Metadata
# Operating system that the job will run on
runs-on: ubuntu-slim
# Sets the scopes available to the github_token injected to the GH Actions runner
permissions:
# Read the files in the repository to be able to compute the version from the package.json.
contents: read
# Set of data that will be made available to downstream jobs.
outputs:
channel: ${{ steps.computedChannel.outputs.channel }}
environment: ${{ steps.computedGitHubEnvironment.outputs.environment }}
shortSha: ${{ steps.shortSha.outputs.shortSha }}
version: ${{ steps.computedVersion.outputs.version }}
semver: ${{ steps.semver.outputs.semver }}
nodeRuntime: ${{ steps.computedNodeRuntime.outputs.runtime }}
# Set of actions to perform for this execution sandbox
steps:
# Download the source code
- name: Checkout Files from Repo
uses: actions/checkout@v7
# Extract the minimum supported Node.JS runtime before setting it up.
- name: Extract Required Node.JS Runtime
id: computedNodeRuntime
run: echo "runtime=$(node ./scripts/get-minimum-node-runtime.ts)" >> "$GITHUB_OUTPUT"
# Ensure npm commands run with the Node version required by the package.
- name: Set up Node.JS Runtime
uses: actions/setup-node@v7
with:
node-version: ${{ steps.computedNodeRuntime.outputs.runtime }}
# Extract the project version from the package.json
- name: Extract Project Version
id: computedVersion
background: true
run: echo "version=$(npm pkg get version --workspaces=false | tr -d \")" >> "$GITHUB_OUTPUT"
# Set the experimental tag to indicate if it is an Alpha or Beta build
- name: Compute Channel
id: computedChannel
background: true
run: |
if [ "${{ inputs.isRelease }}" = "true" ] && [ "${{ inputs.isPrerelease }}" = "true" ]; then
echo "channel=beta" >> "$GITHUB_OUTPUT"
elif [ "${{ inputs.isRelease }}" = "true" ]; then
echo "channel=stable" >> "$GITHUB_OUTPUT"
else
echo "channel=alpha" >> "$GITHUB_OUTPUT"
fi
# Get the first 7 chars of the SHA hash that represents the current commit that the build is operating off of.
- name: Compute Short SHA - Experimental Channel
id: shortSha
background: true
run: echo "shortSha=$(echo ${{ github.sha }} | head -c 7)" >> "$GITHUB_OUTPUT"
# Bring job back to sync execution by awaiting for all async jobs to finish before continuing
- name: Steps - Convert Back To Synchronous Execution
wait-all: true
# Concatenates all previous computed values to generate the semver
- name: Calculate Final Semver
id: semver
run: |
if [ "${{ steps.computedChannel.outputs.channel }}" != "stable" ]; then
echo "semver=${{ steps.computedVersion.outputs.version }}-${{ steps.computedChannel.outputs.channel }}.${{ steps.shortSha.outputs.shortSha }}" >> "$GITHUB_OUTPUT"
else
echo "semver=${{ steps.computedVersion.outputs.version }}" >> "$GITHUB_OUTPUT"
fi
# Publish the resolved project version to the GitHub Actions job summary.
- name: Publish Metadata Summary
run: |
echo "## Build Metadata" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "Project version: \`${{ steps.semver.outputs.semver }}\`" >> "$GITHUB_STEP_SUMMARY"
echo "Channel: \`${{ steps.computedChannel.outputs.channel }}\`" >> "$GITHUB_STEP_SUMMARY"