|
| 1 | +name: Create Release |
| 2 | +# This workflow gathers the version number and the relevant files |
| 3 | +# and creates and pushes a Tag and a Release with them. |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - master |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + release: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + env: |
| 18 | + # path to the release files |
| 19 | + BUILD_PATH: ${{ github.workspace }}/CalibreImport/ReleaseFiles |
| 20 | + |
| 21 | + steps: |
| 22 | + # Checkout repository |
| 23 | + - name: Checkout repository |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + # Set up Git identity |
| 29 | + - name: Set up Git identity |
| 30 | + run: | |
| 31 | + git config --global user.name "${{ github.actor }}" |
| 32 | + git config --global user.email "${{ github.actor }}@tuscoss.com" |
| 33 | +
|
| 34 | + # Check if relevant files have changed |
| 35 | + - name: Check if relevant files have changed |
| 36 | + id: check_files_changed |
| 37 | + run: | |
| 38 | + git fetch origin master |
| 39 | + git checkout master |
| 40 | + CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD -- CalibreImport/ReleaseFiles/CalibreImport.config CalibreImport/ReleaseFiles/*.dll CalibreImport/ReleaseFiles/Setup.ps1 CalibreImport/ReleaseFiles/CalibreImportSetup.exe) |
| 41 | + echo "Changed files: $CHANGED_FILES" |
| 42 | + if [ -n "$CHANGED_FILES" ]; then |
| 43 | + echo "FILES_CHANGED=true" >> $GITHUB_ENV |
| 44 | + else |
| 45 | + echo "FILES_CHANGED=false" >> $GITHUB_ENV |
| 46 | +
|
| 47 | + # Stop workflow if no changes detected |
| 48 | + - name: Stop workflow if no changes detected |
| 49 | + if: env.FILES_CHANGED == 'false' |
| 50 | + run: | |
| 51 | + echo "No relevant changes detected. Stopping workflow." |
| 52 | + exit 0 |
| 53 | +
|
| 54 | + # Extract version from AssemblyInfo.cs and create a tag |
| 55 | + - name: Extract version from AssemblyInfo.cs and create a tag |
| 56 | + if: env.FILES_CHANGED == 'true' |
| 57 | + id: create_tag |
| 58 | + run: | |
| 59 | + current_version=$(grep -Po '(?<=\[assembly: AssemblyVersion\(")([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)' CalibreImport/Properties/AssemblyInfo.cs) |
| 60 | + echo "Current version: $current_version" |
| 61 | + if [ -z "$current_version" ]; then |
| 62 | + echo "Failed to parse current version from AssemblyInfo.cs" |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | + git tag -a "v$current_version" -m "Release version $current_version" |
| 66 | + git push origin "v$current_version" |
| 67 | + echo "NEW_VERSION=$current_version" >> $GITHUB_ENV |
| 68 | +
|
| 69 | + # Extract Assembly Name from .csproj |
| 70 | + - name: Extract Assembly Name from .csproj |
| 71 | + if: env.FILES_CHANGED == 'true' |
| 72 | + id: extract_assembly_name |
| 73 | + run: | |
| 74 | + assembly_name=$(grep -Po '(?<=<AssemblyName>)([^<]+)' CalibreImport/CalibreImport.csproj) |
| 75 | + echo "Assembly name: $assembly_name" |
| 76 | + if [ -z "$assembly_name" ]; then |
| 77 | + echo "Failed to parse assembly name from .csproj" |
| 78 | + exit 1 |
| 79 | + fi |
| 80 | + echo "ASSEMBLY_NAME=$assembly_name" >> $GITHUB_ENV |
| 81 | +
|
| 82 | + # Get commit message |
| 83 | + - name: Get commit message |
| 84 | + id: get_commit_message |
| 85 | + run: | |
| 86 | + COMMIT_MESSAGE=$(git log -1 --pretty=%B HEAD) |
| 87 | + echo "COMMIT_MESSAGE=$COMMIT_MESSAGE" >> $GITHUB_ENV |
| 88 | +
|
| 89 | + # Create the zip file for the release |
| 90 | + - name: Create the zip file for the release |
| 91 | + if: env.FILES_CHANGED == 'true' |
| 92 | + run: | |
| 93 | + mkdir -p release |
| 94 | + cp $BUILD_PATH/*.dll $BUILD_PATH/CalibreImport.config $BUILD_PATH/Setup.ps1 release/ |
| 95 | + zip -r ${{ env.ASSEMBLY_NAME }}-v${{ env.NEW_VERSION }}.zip release/ |
| 96 | + echo "ZIP_FILE=${{ env.ASSEMBLY_NAME }}-v${{ env.NEW_VERSION }}.zip" >> $GITHUB_ENV |
| 97 | +
|
| 98 | + # Copy and rename CalibreImportSetup.exe |
| 99 | + - name: Copy and rename CalibreImportSetup.exe |
| 100 | + if: env.FILES_CHANGED == 'true' |
| 101 | + run: | |
| 102 | + cp $BUILD_PATH/CalibreImportSetup.exe release/CalibreImportSetup-${{ env.NEW_VERSION }}.exe |
| 103 | + echo "SETUP_FILE=release/CalibreImportSetup-${{ env.NEW_VERSION }}.exe" >> $GITHUB_ENV |
| 104 | +
|
| 105 | + # Create Release |
| 106 | + - name: Create Release |
| 107 | + if: env.FILES_CHANGED == 'true' |
| 108 | + id: create_release |
| 109 | + uses: softprops/action-gh-release@v2 |
| 110 | + env: |
| 111 | + GITHUB_TOKEN: ${{ secrets.PAT_GITHUB }} |
| 112 | + with: |
| 113 | + tag_name: v${{ env.NEW_VERSION }} |
| 114 | + name: Release v${{ env.NEW_VERSION }} |
| 115 | + body: ${{ env.COMMIT_MESSAGE }} |
| 116 | + draft: false |
| 117 | + prerelease: false |
| 118 | + files: ${{ env.ZIP_FILE }},${{ env.SETUP_FILE }} |
| 119 | + token: ${{ secrets.PAT_GITHUB }} |
0 commit comments