-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (143 loc) · 5.36 KB
/
release.yml
File metadata and controls
154 lines (143 loc) · 5.36 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
name: Release
on:
push:
branches:
- main
paths:
- force-app
workflow_dispatch:
inputs:
version:
description: Version Number (#.#.#)
required: false
type: string
concurrency:
# Queue releases to prevent version collisions - don't cancel, let them run sequentially
group: release-${{ github.repository }}
cancel-in-progress: false
jobs:
versioning:
name: Versioning
outputs:
version-number: ${{ steps.determine-version.outputs.version-number }}
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Did sfdx-project.json Change?
if: ${{ github.event_name == 'push' }}
id: check-changes
run: |
# Check if sfdx-project.json was modified in the latest commit
if git diff --name-only HEAD~1 HEAD | grep -q "^sfdx-project.json$"; then
echo "sfdx-project.json was modified"
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "sfdx-project.json was not modified"
echo "changed=false" >> "$GITHUB_OUTPUT"
fi
- name: Determine Version
id: determine-version
run: |
# Get current version from sfdx-project.json:
CURRENT_VERSION=$(jq -r '.packageDirectories[] | select(.default == true) | .versionNumber' sfdx-project.json | sed 's/\.NEXT$//')
echo "Current version: $CURRENT_VERSION"
if [[ "${{ github.event_name }}" == "push" && "${{ steps.check-changes.outputs.changed }}" == "false" ]]; then
# 1. On push AND sfdx-project.json was NOT updated - increment the version
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
MAJOR=${VERSION_PARTS[0]}
MINOR=${VERSION_PARTS[1]}
PATCH=${VERSION_PARTS[2]}
NEW_PATCH=$((PATCH + 1))
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
echo "Auto-incremented version to: $NEW_VERSION"
elif [[ "${{ github.event_name }}" == "workflow_dispatch" && -n "${{ inputs.version }}" ]]; then
# 2. On workflow dispatch & a version input is provided - use the version input
NEW_VERSION="${{ inputs.version }}"
echo "Using input version: $NEW_VERSION"
else
# 3. Else - use the existing version number
NEW_VERSION="$CURRENT_VERSION"
echo "Using current version: $NEW_VERSION"
fi
echo "version-number=$NEW_VERSION" >> "$GITHUB_OUTPUT"
- name: Validate Package Version
env:
VERSION: ${{ steps.determine-version.outputs.version-number }}
run: |
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "ERROR: Version '$VERSION' is not valid semver format. Expected 'MAJOR.MINOR.PATCH'"
exit 1
fi
create-managed-package-version:
name: Create Managed Package Version
needs: versioning
permissions:
contents: write
uses: ./.github/workflows/packaging.yml
secrets: inherit
with:
package: managed
version: ${{ needs.versioning.outputs.version-number }}
create-unlocked-package-version:
name: Create Unlocked Package Version
needs: [versioning, create-managed-package-version]
permissions:
contents: write
uses: ./.github/workflows/packaging.yml
secrets: inherit
with:
package: unlocked
version: ${{ needs.versioning.outputs.version-number }}
create-release:
name: Create Release
needs: [versioning, create-managed-package-version, create-unlocked-package-version]
if: ${{ success() && needs.create-managed-package-version.outputs.version-id != '' && needs.create-unlocked-package-version.outputs.version-id != '' }}
permissions:
contents: write
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Draft Release Body
id: release-body
run: |
VERSION="${{ needs.versioning.outputs.version-number }}"
MANAGED_ID="${{ needs.create-managed-package-version.outputs.version-id }}"
UNLOCKED_ID="${{ needs.create-unlocked-package-version.outputs.version-id }}"
# Start building release body
{
echo "## Installation"
echo ""
echo "### Managed Package"
echo "**Package Version**: \`$MANAGED_ID\`"
echo "\`\`\`bash"
echo "sf package install --package $MANAGED_ID --wait 20"
echo "\`\`\`"
echo ""
echo "### Unlocked Package"
echo "**Package Version**: \`$UNLOCKED_ID\`"
echo "\`\`\`bash"
echo "sf package install --package $UNLOCKED_ID --wait 20"
echo "\`\`\`"
echo ""
echo "---"
echo ""
} > release_body.md
# Set as output for next step
{
echo 'body<<EOF'
cat release_body.md
echo 'EOF'
} >> "$GITHUB_OUTPUT"
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v2.3.2
with:
body: ${{ steps.release-body.outputs.body }}
generate_release_notes: true
make_latest: true
tag_name: v${{ needs.versioning.outputs.version-number }}
token: ${{ secrets.GITHUB_TOKEN }}