|
| 1 | +# This workflow runs on every new tag created, and builds the app for 3 platforms (mac, windows, linux). |
| 2 | +# It also creates a new release on the repo's Release page, and uploads the artifacts to there. |
| 3 | +# |
| 4 | +# Usage: |
| 5 | +# git commit -m "Release v0.9.2" |
| 6 | +# git push origin v0.9.2 |
| 7 | +run-name: Build & Release |
| 8 | + |
| 9 | +on: |
| 10 | + push: |
| 11 | + tags: |
| 12 | + - 'v*' |
| 13 | + |
| 14 | +jobs: |
| 15 | + release: |
| 16 | + name: ${{ matrix.os == 'macos-latest' && 'Mac' || 'Linux' }} |
| 17 | + runs-on: ${{ matrix.os }} |
| 18 | + strategy: |
| 19 | + matrix: |
| 20 | + os: [macos-latest, ubuntu-latest] |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Check out Git repository |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + fetch-tags: true |
| 28 | + |
| 29 | + - name: Get semver string |
| 30 | + id: semver_parser |
| 31 | + uses: booxmedialtd/ws-action-parse-semver@v1 |
| 32 | + with: |
| 33 | + version_extractor_regex: 'v(.*)' |
| 34 | + input_string: ${{ github.ref_name }} |
| 35 | + |
| 36 | + - name: Get previous tag |
| 37 | + run: | |
| 38 | + PREVTAG=$(git describe --abbrev=0 --tags "${{ github.ref }}^") |
| 39 | + echo "PREVTAG=$PREVTAG" >> $GITHUB_ENV |
| 40 | +
|
| 41 | + - name: Get version from package.json |
| 42 | + run: | |
| 43 | + echo PKGJSONVERSION=$(jq -r '.version' package.json) >> $GITHUB_ENV |
| 44 | +
|
| 45 | + - name: Version check |
| 46 | + run: | |
| 47 | + if [ "${{ env.PKGJSONVERSION }}" != "${{ steps.semver_parser.outputs.fullversion }}" ]; then |
| 48 | + echo "Version mismatch: \"${{ env.PKGJSONVERSION }}\" != \""${{ steps.semver_parser.outputs.fullversion }}"\"" |
| 49 | + echo "You need to update the version number in package.json" |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | +
|
| 53 | + - name: Generate Changelog Body |
| 54 | + if: matrix.os == 'macos-latest' |
| 55 | + run: | |
| 56 | + echo -e "# Sidenoder \`${{ github.ref_name }}\`" > changelog-body.md |
| 57 | +
|
| 58 | + git log ${{env.PREVTAG}}..HEAD^1 --pretty=format:"%s" | sort -f | while read line; do |
| 59 | + line="$(tr '[:lower:]' '[:upper:]' <<< ${line:0:1})${line:1}" |
| 60 | +
|
| 61 | + case $line in |
| 62 | + [Ff]eat*) |
| 63 | + line=$(echo $line | sed -E "s/^[Ff]eat\(?.*\)?: //") |
| 64 | + echo "- $line" >> commits-feat;; |
| 65 | + [Ff]ix*) |
| 66 | + line=$(echo $line | sed -E "s/^[Ff]ix\(?.*\)?: //") |
| 67 | + echo "- $line" >> commits-fix;; |
| 68 | + [Pp]erf*) |
| 69 | + line=$(echo $line | sed -E "s/^[Pp]erf\(?.*\)?: //") |
| 70 | + echo "- $line" >> commits-perf;; |
| 71 | + [Ss]tyle*) |
| 72 | + line=$(echo $line | sed -E "s/^[Ss]tyle\(?.*\)?: //") |
| 73 | + echo "- $line" >> commits-style;; |
| 74 | + [Mm]erge*) |
| 75 | + # Skip merge commits |
| 76 | + ;; |
| 77 | + *) |
| 78 | + echo "- $line" >> commits-other;; |
| 79 | + esac |
| 80 | + done |
| 81 | +
|
| 82 | + if [ -s commits-feat ]; then |
| 83 | + echo -e "\n## New Features\n\n$(cat commits-feat)" > commits-feat |
| 84 | + cat commits-feat >> changelog-body.md |
| 85 | + fi |
| 86 | +
|
| 87 | + if [ -s commits-fix ]; then |
| 88 | + echo -e "\n## Fixes\n\n$(cat commits-fix)" > commits-fix |
| 89 | + cat commits-fix >> changelog-body.md |
| 90 | + fi |
| 91 | +
|
| 92 | + if [ -s commits-perf ]; then |
| 93 | + echo -e "\n## Performance Improvements\n\n$(cat commits-perf)" > commits-perf |
| 94 | + cat commits-perf >> changelog-body.md |
| 95 | + fi |
| 96 | +
|
| 97 | + if [ -s commits-style ]; then |
| 98 | + echo -e "\n## Style Changes\n\n$(cat commits-style)" > commits-style |
| 99 | + cat commits-style >> changelog-body.md |
| 100 | + fi |
| 101 | +
|
| 102 | + if [ -s commits-other ]; then |
| 103 | + echo -e "\n## Other Changes\n\n$(cat commits-other)" > commits-other |
| 104 | + cat commits-other >> changelog-body.md |
| 105 | + fi |
| 106 | +
|
| 107 | + echo -e "\n---\n\n" >> changelog-body.md |
| 108 | + echo -e "### View the full changelog [here](https://github.com/MikeRatcliffe/sidenoder/compare/${{env.PREVTAG}}...${{ github.ref_name }})." >> changelog-body.md |
| 109 | +
|
| 110 | + - name: Install Node.js, NPM and Yarn |
| 111 | + uses: actions/setup-node@v4 |
| 112 | + with: |
| 113 | + node-version: 22.x |
| 114 | + |
| 115 | + - name: Clobber And Install Dependencies |
| 116 | + run: | |
| 117 | + npm run clobber |
| 118 | + npm install |
| 119 | +
|
| 120 | + - name: Build (Mac) |
| 121 | + if: matrix.os == 'macos-latest' |
| 122 | + run: | |
| 123 | + npm run dist-mac |
| 124 | + env: |
| 125 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 126 | + |
| 127 | + - name: Install Wine (Windows) |
| 128 | + if: matrix.os == 'ubuntu-latest' |
| 129 | + run: | |
| 130 | + sudo dpkg --add-architecture i386 |
| 131 | + sudo apt-get update |
| 132 | + sudo apt-get install wine32 wine64 |
| 133 | +
|
| 134 | + - name: Build (Windows & Linux) |
| 135 | + if: matrix.os == 'ubuntu-latest' |
| 136 | + run: npm run dist-win-linux |
| 137 | + env: |
| 138 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 139 | + |
| 140 | + - name: Push Build To Releases (Mac) |
| 141 | + if: matrix.os == 'macos-latest' |
| 142 | + uses: ncipollo/release-action@v1 |
| 143 | + with: |
| 144 | + tag: v${{ steps.semver_parser.outputs.fullversion }} |
| 145 | + allowUpdates: true |
| 146 | + artifactErrorsFailBuild: true |
| 147 | + bodyFile: changelog-body.md |
| 148 | + generateReleaseNotes: false |
| 149 | + makeLatest: false |
| 150 | + prerelease: ${{ steps.semver_parser.outputs.prerelease != ''}} |
| 151 | + replacesArtifacts: false |
| 152 | + artifacts: /tmp/out/sidenoder*.dmg |
| 153 | + env: |
| 154 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 155 | + |
| 156 | + - name: Push Builds To Releases (Windows & Linux) |
| 157 | + if: matrix.os == 'ubuntu-latest' |
| 158 | + uses: ncipollo/release-action@v1 |
| 159 | + with: |
| 160 | + tag: v${{ steps.semver_parser.outputs.fullversion }} |
| 161 | + allowUpdates: true |
| 162 | + artifactErrorsFailBuild: true |
| 163 | + generateReleaseNotes: false |
| 164 | + makeLatest: true |
| 165 | + omitBody: true |
| 166 | + prerelease: ${{ steps.semver_parser.outputs.prerelease != ''}} |
| 167 | + replacesArtifacts: false |
| 168 | + artifacts: | |
| 169 | + /tmp/out/sidenoder*.exe |
| 170 | + /tmp/out/sidenoder*.AppImage |
| 171 | + /tmp/out/sidenoder*.deb |
| 172 | + /tmp/out/sidenoder*.rpm |
| 173 | + env: |
| 174 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments