-
Notifications
You must be signed in to change notification settings - Fork 0
176 lines (152 loc) · 6.04 KB
/
release.yml
File metadata and controls
176 lines (152 loc) · 6.04 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
name: Create Release
# This workflow gathers the version number and the relevant files
# and creates and pushes a Tag and a Release with them.
on:
push:
branches:
- master
# Prevent concurrent builds that might interfere with each other
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
pull-requests: write
jobs:
release:
runs-on: ubuntu-latest
env:
# path to the release files
BUILD_PATH: ${{ github.workspace }}/CalibreImport/ReleaseFiles
steps:
# Checkout repository
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
# Set up Git identity
- name: Set up Git identity
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@tuscoss.com"
# Check if relevant files have changed
- name: Check if relevant files have changed
id: check_files_changed
run: |
git fetch origin master
git checkout master
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD -- CalibreImport/ReleaseFiles/*.dll CalibreImport/ReleaseFiles/Setup.ps1 CalibreImport/ReleaseFiles/CalibreImportSetup.exe)
echo "Changed files: $CHANGED_FILES"
if [ -n "$CHANGED_FILES" ]; then
echo "FILES_CHANGED=true" >> $GITHUB_ENV
else
# echo "FILES_CHANGED=false" >> $GITHUB_ENV
echo "FILES_CHANGED=true" >> $GITHUB_ENV
fi
# Stop workflow if no changes detected
- name: Stop workflow if no changes detected
if: env.FILES_CHANGED == 'false'
run: |
echo "No relevant changes detected. Stopping workflow."
exit 0 # commenting this out to debug
# Extract version from AssemblyInfo.cs and create a tag
- name: Extract version from AssemblyInfo.cs and create a tag
if: env.FILES_CHANGED == 'true'
id: create_tag
run: |
current_version=$(grep -Po '(?<=\[assembly: AssemblyVersion\(")([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)' CalibreImport/Properties/AssemblyInfo.cs)
echo "Current version: $current_version"
if [ -z "$current_version" ]; then
echo "Failed to parse current version from AssemblyInfo.cs"
exit 1
fi
# Check if tag already exists
if git rev-parse "v$current_version" >/dev/null 2>&1; then
echo "Tag v$current_version already exists. Skipping tag creation."
else
git tag -a "v$current_version" -m "Release version $current_version"
git push origin "v$current_version"
fi
echo "NEW_VERSION=$current_version" >> $GITHUB_ENV
# Extract Assembly Name from .csproj
- name: Extract Assembly Name from .csproj
if: env.FILES_CHANGED == 'true'
id: extract_assembly_name
run: |
assembly_name=$(grep -Po '(?<=<AssemblyName>)([^<]+)' CalibreImport/CalibreImport.csproj)
echo "Assembly name: $assembly_name"
if [ -z "$assembly_name" ]; then
echo "Failed to parse assembly name from .csproj"
exit 1
fi
echo "ASSEMBLY_NAME=$assembly_name" >> $GITHUB_ENV
# Get commit message
- name: Get commit message
id: get_commit_message
run: |
# Escape special characters in commit message
COMMIT_MESSAGE=$(git log -1 --pretty=%B HEAD | sed 's/"/\\"/g')
echo "COMMIT_MESSAGE=$COMMIT_MESSAGE" >> $GITHUB_ENV
# Debug information
- name: Debug info
if: env.FILES_CHANGED == 'true'
run: |
echo "Environment variables:"
echo "ASSEMBLY_NAME: ${{ env.ASSEMBLY_NAME }}"
echo "NEW_VERSION: ${{ env.NEW_VERSION }}"
echo "Files in build path:"
ls -la $BUILD_PATH
# Create the zip file for the release
- name: Create the zip file for the release
if: env.FILES_CHANGED == 'true'
run: |
mkdir -p release
# Check if required files exist
if [ ! -d "$BUILD_PATH" ]; then
echo "Error: Build path does not exist: $BUILD_PATH"
exit 1
fi
# no need to include the default config file, the app will create it dynamically.
# if [ ! -f "$BUILD_PATH/CalibreImport.config" ] || [ ! -f "$BUILD_PATH/Setup.ps1" ]; then
# echo "Warning: Some config files are missing. Continuing anyway."
# fi
# Copy files with error handling
cp $BUILD_PATH/*.dll $BUILD_PATH/Setup.ps1 release/ || {
echo "Warning: Some files could not be copied. Continuing with available files."
}
zip -r ${{ env.ASSEMBLY_NAME }}-v${{ env.NEW_VERSION }}.zip release/ || {
echo "Error: Failed to create zip file"
exit 1
}
echo "ZIP_FILE=${{ env.ASSEMBLY_NAME }}-v${{ env.NEW_VERSION }}.zip" >> $GITHUB_ENV
# Copy and rename CalibreImportSetup.exe
- name: Copy and rename CalibreImportSetup.exe
if: env.FILES_CHANGED == 'true'
run: |
# Check if setup exe exists
if [ ! -f "$BUILD_PATH/${{ env.ASSEMBLY_NAME }}Setup.exe" ]; then
echo "Error: Setup executable not found: $BUILD_PATH/${{ env.ASSEMBLY_NAME }}Setup.exe"
exit 1
fi
cp "$BUILD_PATH/${{ env.ASSEMBLY_NAME }}Setup.exe" "release/${{ env.ASSEMBLY_NAME }}Setup-${{ env.NEW_VERSION }}.exe" || {
echo "Error: Failed to copy setup executable"
exit 1
}
echo "SETUP_FILE=release/${{ env.ASSEMBLY_NAME }}Setup-${{ env.NEW_VERSION }}.exe" >> $GITHUB_ENV
# Create Release
- name: Create Release
if: env.FILES_CHANGED == 'true'
id: create_release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.PAT_GITHUB }}
with:
tag_name: v${{ env.NEW_VERSION }}
name: Release v${{ env.NEW_VERSION }}
body: ${{ env.COMMIT_MESSAGE }}
draft: false
prerelease: false
files: |
${{ env.ZIP_FILE }}
${{ env.SETUP_FILE }}
token: ${{ secrets.PAT_GITHUB }}