Просмотр исходного кода

Merge pull request #53 from derskythe/master

Modify GitHub workflow to generate releases
DerSkythe 2 лет назад
Родитель
Сommit
b574fa373d
3 измененных файлов с 122 добавлено и 93 удалено
  1. 21 0
      .github/release.yml
  2. 80 93
      .github/workflows/build-with-firmware.yml
  3. 21 0
      .github/workflows/stale.yml

+ 21 - 0
.github/release.yml

@@ -0,0 +1,21 @@
+changelog:
+  exclude:
+    labels:
+      - ignore-for-release
+  categories:
+    - title: Breaking Changes 🛠
+      labels:
+        - breaking-change
+    - title: Exciting New Features 🎉
+      labels:
+        - enhancement
+    - title: Bug fixes🧑‍🔧 🐞
+      labels:
+        - bug
+    - title: Doc improvements 📚
+      labels:
+        - docs
+        - documentation
+    - title: Other Changes
+      labels:
+        - "*"

+ 80 - 93
.github/workflows/build-with-firmwware.yml → .github/workflows/build-with-firmware.yml

@@ -1,41 +1,41 @@
-name: "Build for Firmware"
-run-name: "Build ${{ inputs.DEPLOY_TARGET }} by @${{ github.ACTOR }}"
+name: "Build with Firmware"
+run-name: "Build ${{ inputs.DEPLOY_TARGET }} triggered by ${{ github.EVENT_NAME }} (@${{ github.ACTOR }})"
 
 
 on:
 on:
   workflow_dispatch:
   workflow_dispatch:
     inputs:
     inputs:
       version:
       version:
-        description: "Enter version to build or left empty for current version"
+        description: "Enter version to build or left empty for the NEXT version"
         required: false
         required: false
         type: string
         type: string
-  release:
-    types: [created, prereleased]
-  push:
-    paths:
-      - .github/workflows/build-with-firmware.yml
+#  push:
+#    paths:
+#      - .github/workflows/build-with-firmware.yml
 
 
 permissions:
 permissions:
   contents: write
   contents: write
   packages: write
   packages: write
 
 
-concurrency:
-  group: firmware-build-${{ vars.FIRMWARE_VERSION }}-${{ vars.RELEASE_VERSION }}
-  cancel-in-progress: false
+#concurrency:
+#  group: firmware-build-${{ vars.FIRMWARE_VERSION }}-${{ vars.RELEASE_VERSION }}
+#  cancel-in-progress: false
 
 
 jobs:
 jobs:
   build-and-upload:
   build-and-upload:
     runs-on: ubuntu-latest
     runs-on: ubuntu-latest
     env:
     env:
       REPO_SELF: ${{ vars.REPO_SELF }}
       REPO_SELF: ${{ vars.REPO_SELF }}
-      OFW_PATH: "applications_user/subbrute"
+      APP_PATH: "applications_user/subbrute"
       RELATIVE_PATH: "applications/external/subbrute"
       RELATIVE_PATH: "applications/external/subbrute"
-      CURRENT_VERSION: ${{ vars.RELEASE_VERSION }}
-      RELEASE_VERSION: ${{ vars.RELEASE_VERSION }}
+      PREV_TAG: ""
       APP_NAME: ""
       APP_NAME: ""
       ZIP_NAME: ""
       ZIP_NAME: ""
       ZIP_TAG: ""
       ZIP_TAG: ""
       TGZ_NAME: ""
       TGZ_NAME: ""
       TGZ_TAG: ""
       TGZ_TAG: ""
+      SHA: ""
+      FW_VERSION: ""
+      RELEASE_VERSION: ""
     strategy:
     strategy:
       fail-fast: false
       fail-fast: false
       matrix:
       matrix:
@@ -47,90 +47,25 @@ jobs:
             src-included: 0
             src-included: 0
           - firmware: official
           - firmware: official
             url: ${{ vars.REPO_OFFICIAL }}
             url: ${{ vars.REPO_OFFICIAL }}
-            version: "official"
+            version: official
             src-included: 0
             src-included: 0
     steps:
     steps:
-      - name: Set version
-        env:
-          INPUT_VERSION: ${{ inputs.version }}
-          CURRENT_VERSION: ${{ env.CURRENT_VERSION }}
-        shell: pwsh
-        run: |
-          $releaseVersion = ([string]::IsNullOrWhitespace($env:INPUT_VERSION) ? $env:CURRENT_VERSION : $env:INPUT_VERSION)
-          if ( $releaseVersion.StartsWith('v') ) {
-            $releaseVersion = $releaseVersion.Substring(1)
-          }
-          Write-Output ('RELEASE_VERSION={0}' -f $releaseVersion) >> $env:GITHUB_ENV
-
       - name: Copy Firmware Files
       - name: Copy Firmware Files
         uses: actions/checkout@v3
         uses: actions/checkout@v3
         with:
         with:
           repository: ${{ matrix.url }}
           repository: ${{ matrix.url }}
-          clean: "true"
-          submodules: "true"
-          ref: "dev"
+          clean: true
+          submodules: true
+          ref: dev
 
 
       - name: Copy Repo Files
       - name: Copy Repo Files
         if: ${{ matrix.src-included == 0 }}
         if: ${{ matrix.src-included == 0 }}
         uses: actions/checkout@v3
         uses: actions/checkout@v3
         with:
         with:
           repository: ${{ vars.REPO_SELF }}
           repository: ${{ vars.REPO_SELF }}
-          clean: "true"
-          submodules: "true"
-          path: "${{ env.OFW_PATH }}"
-
-      - name: Print vars about state or repo if Unleashed
-        if: ${{ matrix.src-included == 1 }}
-        shell: pwsh
-        run: |
-          git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1
-          git submodule set-branch --branch master '${{ env.RELATIVE_PATH }}'
-          git submodule sync '${{ env.RELATIVE_PATH }}'
-          cd '${{ env.OFW_PATH }}'
-          if ( '${{ env.CURRENT_VERSION }}' -ne '${{ env.RELEASE_VERSION }}' ) {
-            Write-Output '::warning title=Different version::Current version is ${{ env.CURRENT_VERSION }} but we trying to build ${{ env.RELEASE_VERSION }}'
-            
-            git checkout tags/v${{ env.RELEASE_VERSION }} -b tmp-build
-            
-            if ( $LASTEXITCODE -ne 0 ) {
-              Write-Error '::error title=Cannot checkout to this version::Error during execution checkout to this tag ${{ env.RELEASE_VERSION }}'
-              exit 1
-            }
-          }
-
-          $output = (git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1)
-
-          if ( $LASTEXITCODE -ne 0 ) {
-            Write-Error '::error title=Invalid checkout::Invalid checkout'
-            exit 1
-          }
-          Write-Output ('::notice title=Git output::{0}' -f $output)
-
-      - name: Print vars about state or repo if Official
-        if: ${{ matrix.src-included == 0 }}
-        shell: pwsh
-        run: |
-          git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1
-          cd '${{ env.OFW_PATH }}'
-
-          if ( '${{ env.CURRENT_VERSION }}' -ne '${{ env.RELEASE_VERSION }}' ) {
-            Write-Output '::warning title=Different version::Current version is ${{ env.CURRENT_VERSION }} but we trying to build ${{ env.RELEASE_VERSION }}'
-            
-            git checkout tags/v${{ env.RELEASE_VERSION }} -b tmp-build
-
-            if ( $LASTEXITCODE -ne 0 ) {
-              Write-Error '::error title=Cannot checkout to this version::Error during execution checkout to this tag ${{ env.RELEASE_VERSION }}'
-              exit 1
-            }
-          } else {
-            $output = (git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1)
-
-            if ( $LASTEXITCODE -ne 0 ) {
-              Write-Error '::error title=Invalid checkout::Invalid checkout'
-              exit 1
-            }
-            Write-Output ('::notice title=Git output::{0}' -f $output)
-          }
+          clean: true
+          submodules: true
+          path: ${{ env.APP_PATH }}
 
 
       #    - name: Restore FBT
       #    - name: Restore FBT
       #      id: cache-restore
       #      id: cache-restore
@@ -145,11 +80,53 @@ jobs:
       #
       #
       - name: Remove other apps
       - name: Remove other apps
         shell: pwsh
         shell: pwsh
-        if: ${{ success() }}
         # rm to remove problem FAP which includes non-existent files
         # rm to remove problem FAP which includes non-existent files
         run: |
         run: |
           Remove-Item -Force -Recurse ./applications/debug -ErrorAction SilentlyContinue
           Remove-Item -Force -Recurse ./applications/debug -ErrorAction SilentlyContinue
           Remove-Item -Force -Recurse ./applications/examples -ErrorAction SilentlyContinue
           Remove-Item -Force -Recurse ./applications/examples -ErrorAction SilentlyContinue
+          Remove-Item -Force -Recurse ${{ env.RELATIVE_PATH }} -ErrorAction SilentlyContinue
+
+      - name: Get SHA of our application and release version
+        shell: pwsh
+        env:
+          GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }}
+          INPUT_VERSION: ${{ inputs.version }}
+        run: |
+          Write-Output "::notice title=${{ matrix.firmware }} Input Version Number::v${{ inputs.version }}"
+          $fwInfo = ((gh release view --json tagName,url -R ${{ matrix.url }}) | ConvertFrom-Json)
+          cd '${{ env.APP_PATH }}'
+          $sha = (git rev-parse --verify HEAD)
+          
+          $releaseVersion = ''
+          $latestTag = ((gh release view --json tagName,url -R ${{ vars.REPO_SELF }}) | ConvertFrom-Json ).tagName
+
+          if ( [string]::IsNullOrWhitespace($env:INPUT_VERSION) ) {            
+            Write-Output "::notice title=${{ matrix.firmware }} Latest tag::$latestTag"
+            
+            $lastIndex = $latestTag.LastIndexOf('.')
+            
+            $minorValue = $latestTag.Substring($latestTag.LastIndexOf('.') + 1)
+            $minorValue = [Convert]::ToInt32($minorValue) + 1
+            $newTag = $latestTag.Substring(0, $lastIndex)
+            
+            $releaseVersion = ('{0}.{1}' -f $newTag, $minorValue)
+          } else {
+            $releaseVersion = "$env:INPUT_VERSION"
+          }
+          
+          if ( $releaseVersion.StartsWith('v') ) {
+            $releaseVersion = $releaseVersion.Substring(1)
+          }
+          
+          Write-Output "::notice title=${{ matrix.firmware }} PREV_TAG::$latestTag"
+          Write-Output "::notice title=${{ matrix.firmware }} RELEASE_VERSION::$releaseVersion"
+          Write-Output "::notice title=${{ matrix.firmware }} SHA::$sha"
+          Write-Output ('::notice title=${{ matrix.firmware }} FW_VERSION::{0}' -f $fwInfo.tagName)
+          
+          Write-Output ('RELEASE_VERSION={0}' -f $releaseVersion) >> $env:GITHUB_ENV
+          Write-Output ('SHA={0}' -f $sha) >> $env:GITHUB_ENV
+          Write-Output ('FW_VERSION={0}' -f $fwInfo.tagName) >> $env:GITHUB_ENV
+          Write-Output ('PREV_TAG={0}' -f $latestTag) >> $env:GITHUB_ENV
 
 
       - name: Build Firmware
       - name: Build Firmware
         shell: bash
         shell: bash
@@ -187,7 +164,7 @@ jobs:
         if: ${{ success() }}
         if: ${{ success() }}
         shell: pwsh
         shell: pwsh
         env:
         env:
-          APP_NAME: "subghz_bruteforcer_${{ env.RELEASE_VERSION }}_${{ matrix.firmware }}"
+          APP_NAME: "subghz_bruteforcer_${{ env.RELEASE_VERSION }}"
         run: |
         run: |
           function Format-Bytes {
           function Format-Bytes {
             param(
             param(
@@ -207,8 +184,14 @@ jobs:
                   }
                   }
               }
               }
           }
           }
-          $zipName = ('{0}.zip' -f $env:APP_NAME)
-          $tgzName = ('{0}.tgz' -f $env:APP_NAME)
+          $appName = $env:APP_NAME
+          if ( '${{ matrix.firmware }}' -eq 'unlshd' ) {
+            $appName = ('{0}_${{ env.FW_VERSION }}' -f $appName)
+          } else {
+            $appName = ('{0}_${{ matrix.firmware}}-${{ env.FW_VERSION }}' -f $appName)
+          }
+          $zipName = ('{0}.zip' -f $appName)
+          $tgzName = ('{0}.tgz' -f $appName)
           $fapName = 'subghz_bruteforcer.fap'
           $fapName = 'subghz_bruteforcer.fap'
           $dstFap = "./$fapName"
           $dstFap = "./$fapName"
           $appDir = "dist/f7-C/apps/Sub-GHz"
           $appDir = "dist/f7-C/apps/Sub-GHz"
@@ -244,9 +227,13 @@ jobs:
         env:
         env:
           GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }}
           GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }}
         run: |
         run: |
-          $url = (gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${{ github.REPOSITORY }}/releases/tags/${{ env.RELEASE_VERSION }}) | ConvertFrom-Json -AsHashtable
-          if ( [string]::IsNullOrWhitespace($url) ) {
-            gh release create v${{ env.RELEASE_VERSION }} --generate-notes --draft -R ${{ env.REPO_SELF }}  
+          $mime = "Accept: application/vnd.github+json"
+          $api = "X-GitHub-Api-Version: 2022-11-28"
+          $json = (gh api -H $mime -H $api /repos/${{ github.REPOSITORY }}/releases) | ConvertFrom-Json
+          $tagExists = ($json.GetEnumerator() | Where-Object { $_.tag_name -eq 'v${{ env.RELEASE_VERSION }}' }) -ne $null
+          if ( $tagExists -eq $false ) {
+            gh api --method POST -H $mime -H $api /repos/${{ github.REPOSITORY }}/releases -f tag_name='v${{ env.RELEASE_VERSION }}' -f target_commitish='${{ env.SHA }}' -f name='v${{ env.RELEASE_VERSION }}' -F draft=true -F prerelease=false -F generate_release_notes=false  
+            gh api --method POST -H $mime -H $api /repos/${{ github.REPOSITORY }}/releases/generate-notes -f tag_name='v${{ env.RELEASE_VERSION }}' -f target_commitish='${{ env.SHA }}' -f previous_tag_name='${{ env.PREV_TAG }}'
           }          
           }          
           gh release upload 'v${{ env.RELEASE_VERSION }}' '${{ env.ZIP_NAME }}#${{ env.ZIP_TAG }}' '${{ env.TGZ_NAME }}#${{ env.TGZ_TAG }}' --clobber -R ${{ env.REPO_SELF }}
           gh release upload 'v${{ env.RELEASE_VERSION }}' '${{ env.ZIP_NAME }}#${{ env.ZIP_TAG }}' '${{ env.TGZ_NAME }}#${{ env.TGZ_TAG }}' --clobber -R ${{ env.REPO_SELF }}
           gh release edit 'v${{ env.RELEASE_VERSION }}' --draft=false -R ${{ env.REPO_SELF }}
           gh release edit 'v${{ env.RELEASE_VERSION }}' --draft=false -R ${{ env.REPO_SELF }}

+ 21 - 0
.github/workflows/stale.yml

@@ -0,0 +1,21 @@
+name: "Close stale issues and PRs"
+on:
+  schedule:
+    - cron: "* 0 * * *"
+
+jobs:
+  stale:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/stale@v8
+        with:
+          days-before-stale: -1
+          days-before-close: -1
+          stale-pr-message: "This pull request is stale because it has been open 14 days with no activity. To keep this pull request open remove stale label or comment."
+          stale-pr-label: "status:stale"
+          close-pr-message: "This pull request was closed because it has been stale for 14 days with no activity. If this pull request is important or you have more to add feel free to re-open it."
+          days-before-pr-stale: 14
+          days-before-pr-close: 14
+          exempt-issue-labels: "needs:attention,needs:triage,blocked"
+          ascending: true # https://github.com/actions/stale#ascending
+          operations-per-run: 500