|
| 1 | +name: Build and Release latest version |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: main |
| 6 | + |
| 7 | +jobs: |
| 8 | + check_build_number: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + outputs: |
| 11 | + number: ${{ steps.check_number.outputs.number }} |
| 12 | + new_release: ${{ steps.check_number.outputs.new_release }} |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout VERSION |
| 16 | + uses: actions/checkout@v3 |
| 17 | + with: |
| 18 | + sparse-checkout: | |
| 19 | + VERSION |
| 20 | + sparse-checkout-cone-mode: false |
| 21 | + |
| 22 | + - name: Check latest release and current version number |
| 23 | + id: check_number |
| 24 | + run: | |
| 25 | + latest_release_json=$(curl -L \ |
| 26 | + -H "Accept: application/vnd.github+json" \ |
| 27 | + -H "Authorization: Bearer ${{ secrets.ACCESS_TOKEN }}" \ |
| 28 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 29 | + "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/latest") |
| 30 | +
|
| 31 | + latest_release_tag=$(echo "$latest_release_json" | jq -r .tag_name) |
| 32 | + current_version=$(head -1 VERSION) |
| 33 | +
|
| 34 | + echo "Latest release version: $latest_release_tag" |
| 35 | + echo "Current version: $current_version" |
| 36 | +
|
| 37 | + if [ "$latest_release_tag" == "$current_version" ]; then |
| 38 | + echo "Release already exists" |
| 39 | + echo "new_release=false" >> "$GITHUB_OUTPUT" |
| 40 | + else |
| 41 | + echo "New release" |
| 42 | + echo "number=$(head -1 VERSION)" >> "$GITHUB_OUTPUT" |
| 43 | + fi |
| 44 | +
|
| 45 | + build_executables: |
| 46 | + needs: check_build_number |
| 47 | + if: needs.check_build_number.outputs.new_release != 'false' |
| 48 | + strategy: |
| 49 | + matrix: |
| 50 | + os: [ubuntu-latest, windows-latest] |
| 51 | + runs-on: ${{ matrix.os }} |
| 52 | + env: |
| 53 | + PYTHON_VERSION: "3.12" |
| 54 | + |
| 55 | + steps: |
| 56 | + - name: Checkout repository |
| 57 | + uses: actions/checkout@v3 |
| 58 | + |
| 59 | + - name: Set up Python ${{ env.PYTHON_VERSION }} |
| 60 | + uses: actions/setup-python@v3 |
| 61 | + with: |
| 62 | + python-version: ${{ env.PYTHON_VERSION }} |
| 63 | + |
| 64 | + - name: Install dependencies |
| 65 | + run: | |
| 66 | + python -m pip install --upgrade pip |
| 67 | + pip install pyinstaller |
| 68 | + |
| 69 | + - name: Create a one-file bundled executable |
| 70 | + run: pyinstaller -n app_${{ needs.check_build_number.outputs.number }}_${{ runner.os }} -F src/main.py |
| 71 | + |
| 72 | + - name: Upload executable |
| 73 | + uses: actions/upload-artifact@v4 |
| 74 | + with: |
| 75 | + name: ${{ needs.check_build_number.outputs.number }}-${{ runner.os }} |
| 76 | + path: dist/ |
| 77 | + |
| 78 | + release_build: |
| 79 | + needs: [check_build_number, build_executables] |
| 80 | + runs-on: ubuntu-latest |
| 81 | + steps: |
| 82 | + - name: Download artifacts |
| 83 | + uses: actions/download-artifact@v4 |
| 84 | + with: |
| 85 | + path: artifacts |
| 86 | + |
| 87 | + - name: Archive artifacts |
| 88 | + run: | |
| 89 | + find "artifacts" -type f | while read -r file; do |
| 90 | + filename=$(basename "$file" .exe) |
| 91 | + zip -j "$(dirname "$file")/$filename.zip" "$file" |
| 92 | + rm "$file" |
| 93 | + done |
| 94 | +
|
| 95 | + - name: Create Release |
| 96 | + id: current_release |
| 97 | + run: | |
| 98 | + release_json=$(curl -L -f \ |
| 99 | + -X POST \ |
| 100 | + -H "Accept: application/vnd.github+json" \ |
| 101 | + -H "Authorization: Bearer ${{ secrets.ACCESS_TOKEN }}" \ |
| 102 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 103 | + https://api.github.com/repos/${GITHUB_REPOSITORY}/releases \ |
| 104 | + -d '{"tag_name":"${{ needs.check_build_number.outputs.number }}","name":"${{ needs.check_build_number.outputs.number }}"}') |
| 105 | + |
| 106 | + echo "release_id=$(echo $release_json | jq -r .id)" >> $GITHUB_OUTPUT |
| 107 | + |
| 108 | + - name: Upload a release assets |
| 109 | + run: | |
| 110 | + find "artifacts" -type f | while read -r file; do |
| 111 | + curl -L -f \ |
| 112 | + -X POST \ |
| 113 | + -H "Accept: application/vnd.github+json" \ |
| 114 | + -H "Authorization: Bearer ${{ secrets.ACCESS_TOKEN }}" \ |
| 115 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 116 | + -H "Content-Type: application/octet-stream" \ |
| 117 | + "https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${{ steps.current_release.outputs.release_id }}/assets?name=$(basename "$file")" \ |
| 118 | + --data-binary "@$file" |
| 119 | + echo "Uploaded: $(basename "$file")" |
| 120 | + done |
0 commit comments