main.yml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. name: UFBT Build and Release
  2. permissions:
  3. contents: write
  4. on:
  5. push:
  6. branches:
  7. - main
  8. pull_request:
  9. branches:
  10. - main
  11. jobs:
  12. build:
  13. name: Build and Test Application
  14. runs-on: ubuntu-latest
  15. steps:
  16. - name: Checkout Repository
  17. uses: actions/checkout@v3
  18. - name: Set up Python
  19. uses: actions/setup-python@v4
  20. with:
  21. python-version: '3.x'
  22. - name: Install UFBT
  23. run: |
  24. python3 -m pip install --upgrade pip
  25. pip install ufbt
  26. - name: Initialize UFBT Environment
  27. run: |
  28. ufbt update
  29. ufbt vscode_dist
  30. - name: Build FAP Applications
  31. run: ufbt faps
  32. - name: Upload Build Artifacts
  33. uses: actions/upload-artifact@v3
  34. with:
  35. name: build-output
  36. path: build/
  37. release:
  38. name: Create Release
  39. needs: build
  40. if: github.event_name == 'push' && github.ref == 'refs/heads/main'
  41. runs-on: ubuntu-latest
  42. steps:
  43. - name: Checkout Repository
  44. uses: actions/checkout@v3
  45. - name: Extract Version from Manifest
  46. id: extract_version
  47. run: |
  48. VERSION=$(grep '^version:' manifest.yml | awk '{print $2}')
  49. echo "VERSION=${VERSION}" >> $GITHUB_ENV
  50. - name: Check if Release Exists
  51. id: check_release
  52. run: |
  53. REPO="luu176/Metroflip"
  54. TAG="v${{ env.VERSION }}"
  55. RELEASE_EXISTS=$(curl -s https://api.github.com/repos/$REPO/releases/tags/$TAG)
  56. echo "RELEASE_EXISTS=$RELEASE_EXISTS"
  57. if [[ $RELEASE_EXISTS == *"Not Found"* ]]; then
  58. echo "Release not found. Creating new release."
  59. echo "create=true" >> $GITHUB_ENV
  60. else
  61. echo "Release found. Deleting existing release."
  62. RELEASE_ID=$(echo $RELEASE_EXISTS | jq -r '.id')
  63. curl -X DELETE -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/$REPO/releases/$RELEASE_ID
  64. echo "create=true" >> $GITHUB_ENV
  65. fi
  66. - name: Create Release
  67. id: create_release
  68. if: env.create == 'true'
  69. uses: actions/create-release@v1
  70. with:
  71. tag_name: v${{ env.VERSION }}
  72. release_name: Metroflip v${{ env.VERSION }}
  73. body: |
  74. **What's New:**
  75. $(cat CHANGELOG.md)
  76. draft: false
  77. prerelease: false
  78. env:
  79. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  80. - name: Upload FAP File to Release
  81. if: env.create == 'true'
  82. uses: actions/upload-release-asset@v1
  83. with:
  84. upload_url: ${{ steps.create_release.outputs.upload_url }}
  85. asset_path: build/fap/metroflip-${{ env.VERSION }}.fap
  86. asset_name: metroflip-${{ env.VERSION }}.fap
  87. asset_content_type: application/octet-stream