|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + tag: |
| 7 | + description: 'Tag for the release (e.g., v1.0.0.0)' |
| 8 | + required: true |
| 9 | + version_name: |
| 10 | + description: 'Version name for the release' |
| 11 | + required: true |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + build-test-release: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout code |
| 22 | + uses: actions/checkout@v2 |
| 23 | + |
| 24 | + - name: Setup Rust |
| 25 | + uses: actions-rs/toolchain@v1 |
| 26 | + with: |
| 27 | + toolchain: stable |
| 28 | + override: true |
| 29 | + |
| 30 | + - name: Install cargo-deb |
| 31 | + run: cargo install cargo-deb |
| 32 | + |
| 33 | + - name: Build project |
| 34 | + run: cargo build --release |
| 35 | + |
| 36 | + - name: Create Debian package |
| 37 | + run: | |
| 38 | + mkdir -p debian/usr/bin |
| 39 | + cp target/release/qud debian/usr/bin/qud |
| 40 | + cargo deb -p qud -o ./qud.deb |
| 41 | + |
| 42 | + - name: Check if release exists |
| 43 | + id: check_release |
| 44 | + run: | |
| 45 | + if gh release view ${{ github.event.inputs.tag }} &>/dev/null; then |
| 46 | + echo "::set-output name=exists::true" |
| 47 | + else |
| 48 | + echo "::set-output name=exists::false" |
| 49 | + fi |
| 50 | + env: |
| 51 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 52 | + |
| 53 | + - name: Create Release |
| 54 | + if: steps.check_release.outputs.exists == 'false' |
| 55 | + id: create_release |
| 56 | + uses: actions/create-release@v1 |
| 57 | + env: |
| 58 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + with: |
| 60 | + tag_name: ${{ github.event.inputs.tag }} |
| 61 | + release_name: ${{ github.event.inputs.version_name }} |
| 62 | + draft: false |
| 63 | + prerelease: false |
| 64 | + |
| 65 | + - name: Upload Release Asset |
| 66 | + if: steps.check_release.outputs.exists == 'false' |
| 67 | + uses: actions/upload-release-asset@v1 |
| 68 | + env: |
| 69 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 70 | + with: |
| 71 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 72 | + asset_path: ./target/release/qud |
| 73 | + asset_name: qud |
| 74 | + asset_content_type: application/octet-stream |
| 75 | + |
| 76 | + - name: Upload Debian Package |
| 77 | + if: steps.check_release.outputs.exists == 'false' |
| 78 | + uses: actions/upload-release-asset@v1 |
| 79 | + env: |
| 80 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 81 | + with: |
| 82 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 83 | + asset_path: ./qud.deb |
| 84 | + asset_name: qud_${{ github.event.inputs.tag }}_amd64.deb |
| 85 | + asset_content_type: application/vnd.debian.binary-package |
| 86 | + |
| 87 | + - name: Release already exists |
| 88 | + if: steps.check_release.outputs.exists == 'true' |
| 89 | + run: | |
| 90 | + echo "Error: A release with the tag ${{ github.event.inputs.tag }} already exists." |
| 91 | + exit 1 |
0 commit comments