-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
159 lines (146 loc) · 5.77 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
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
155
156
157
158
159
name: 'Semrel'
description: 'GitHub Action to detect new versions and generate release notes using semrel'
author: 'Brian Bruggeman'
inputs:
branch:
description: 'Branch to check out'
required: false
default: ''
path:
description: 'Path to project files'
required: false
default: '.'
outputs:
current-version:
description: 'The current version'
value: ${{ steps.semrel.outputs.current-version }}
log:
description: 'Base64 encoded commit log for the next version'
value: ${{ steps.semrel.outputs.log }}
next-version:
description: 'The next version'
value: ${{ steps.semrel.outputs.next-version }}
release-notes:
description: 'Base64 encoded release notes for the next version'
value: ${{ steps.semrel.outputs.release-notes }}
version-changed:
description: 'Identifies if current and next versions are different'
value: ${{ steps.semrel.outputs.version-changed }}
manifest-path:
description: 'Identifies path to manifest file'
value: ${{ steps.semrel.outputs.manifest-path }}
runs:
using: 'composite'
steps:
- name: Checkout code
if: ${{ inputs.branch != '' }}
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
fetch-depth: 0
- name: Install jq
shell: bash
run: sudo apt-get install -y jq
- name: Get latest semrel release data
id: get-release-data
shell: bash
run: |
url="https://api.github.com/repos/brianbruggeman/semrel/releases/latest"
release_data=$(curl --silent $url)
if [ $? -ne 0 ] || [ -z "$release_data" ]; then
echo "Failed to fetch release data from URL: $url"
exit 1
fi
release_data=$(echo "$release_data" | base64 | tr -d '\n')
echo "release_data=$release_data" >> $GITHUB_ENV
- name: Extract tag name
id: extract-tag-name
shell: bash
run: |
release_data=$(echo "${{ env.release_data }}" | base64 --decode)
tag_name=$(echo "$release_data" | jq -r .tag_name)
if [ $? -ne 0 ] || [ -z "$tag_name" ]; then
echo "Failed to extract tag name from release data: $release_data"
exit 1
fi
semrel_filename="semrel-$tag_name-x86_64-unknown-linux-musl"
asset_tag="$semrel_filename.tgz"
echo "semrel_filename=$semrel_filename" >> $GITHUB_ENV
echo "asset_tag=$asset_tag" >> $GITHUB_ENV
- name: Extract assets
id: extract-assets
shell: bash
run: |
release_data=$(echo "${{ env.release_data }}" | base64 --decode)
assets=$(echo "$release_data" | jq -c '.assets[]')
if [ $? -ne 0 ] || [ -z "$assets" ]; then
echo "Failed to extract assets from release data: $release_data"
exit 1
fi
assets=$(echo "$assets" | base64 | tr -d '\n')
echo "assets=$assets" >> $GITHUB_ENV
echo "release_data=" >> $GITHUB_ENV
- name: Find asset ID and URL
id: find-asset-id
shell: bash
run: |
asset_tag=$(echo "${{ env.asset_tag }}")
assets=$(echo "${{ env.assets }}" | base64 --decode)
asset_id=$(echo "$assets" | jq -r --arg asset_tag "$asset_tag" 'select(.name == $asset_tag) | .id')
if [ $? -ne 0 ] || [ -z "$asset_id" ]; then
echo "Failed to find asset ID. Assets: $assets, Asset Tag: $asset_tag"
exit 1
fi
asset_url="https://api.github.com/repos/brianbruggeman/semrel/releases/assets/$asset_id"
echo "asset_id=$asset_id" >> $GITHUB_ENV
echo "asset_url=$asset_url" >> $GITHUB_ENV
echo "assets=" >> $GITHUB_ENV
- name: Download and extract semrel
shell: bash
run: |
curl -L -H "Accept: application/octet-stream" -o ${{ env.semrel_filename }}.tgz ${{ env.asset_url }}
tar -xzf ${{ env.semrel_filename }}.tgz -C . --strip-components=1
chmod +x ${{ env.semrel_filename }}
mv ${{ env.semrel_filename }} ./semrel
- name: Cleanup GITHUB_ENV
shell: bash
run: |
echo "asset_id=" >> $GITHUB_ENV
echo "asset_tag=" >> $GITHUB_ENV
echo "asset_url=" >> $GITHUB_ENV
echo "semrel_filename=" >> $GITHUB_ENV
echo "tag_name=" >> $GITHUB_ENV
- name: Set outputs
id: semrel
shell: bash
run: |
current_version=$(./semrel --path=${{ inputs.path }} show current)
log=$(./semrel --path=${{ inputs.path }} show log)
next_version=$(./semrel --path=${{ inputs.path }} show next)
release_notes=$(./semrel --path=${{ inputs.path }} show notes)
manifest_path=$(./semrel --path=${{ inputs.path }} show manifest)
# Encode multiline outputs to base64 to handle special characters and newlines
encoded_release_notes=$(echo "$release_notes" | base64 | tr -d '\n')
encoded_log=$(echo "$log" | base64 | tr -d '\n')
echo "current-version=$current_version" >> $GITHUB_OUTPUT
echo "next-version=$next_version" >> $GITHUB_OUTPUT
echo "release-notes=$encoded_release_notes" >> $GITHUB_OUTPUT
echo "log=$encoded_log" >> $GITHUB_OUTPUT
echo "manifest-path=$manifest_path" >> $GITHUB_OUTPUT
if [ "$next_version" != "$current_version" ]; then
echo "version-changed=true" >> $GITHUB_OUTPUT
else
echo "version-changed=false" >> $GITHUB_OUTPUT
fi
- name: Debug Outputs
shell: bash
run: |
echo "version-changed: ${{ steps.semrel.outputs.version-changed }}"
echo "current-version: ${{ steps.semrel.outputs.current-version }}"
echo "next-version: ${{ steps.semrel.outputs.next-version }}"
echo "manifest-path: ${{ steps.semrel.outputs.manifest-path }}"
- name: Show commit logs used
shell: bash
run: |
echo "Show commit logs used"
./semrel show log