Skip to content

Commit a89ba3c

Browse files
authored
Merge pull request #11 from derskythe/master
Sync working tree
2 parents 819b532 + 5db74e2 commit a89ba3c

8 files changed

+481
-24
lines changed
+218
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
name: "Build for Firmware"
2+
run-name: "Build ${{ inputs.DEPLOY_TARGET }} by @${{ github.ACTOR }}"
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
version:
8+
description: "Enter version to build or left empty for current version"
9+
required: false
10+
type: string
11+
release:
12+
types: [unpublished]
13+
push:
14+
paths:
15+
- .github/workflows/build-with-firmware.yml
16+
17+
permissions:
18+
contents: write
19+
packages: write
20+
21+
jobs:
22+
build-and-upload:
23+
# runs-on: [self-hosted, linux]
24+
runs-on: ubuntu-latest
25+
concurrency:
26+
group: firmware-build-${{ vars.FIRMWARE_VERSION }}-${{ vars.RELEASE_VERSION }}
27+
cancel-in-progress: false
28+
env:
29+
REPO_SELF: ${{ vars.REPO_SELF }}
30+
IGNORED_PATH: "applications_user/subbrute"
31+
RELATIVE_PATH: "applications/external/subbrute"
32+
CURRENT_VERSION: ${{ vars.RELEASE_VERSION }}
33+
strategy:
34+
fail-fast: false
35+
matrix:
36+
firmware: [unlshd]
37+
include:
38+
- firmware: unlshd
39+
url: ${{ vars.REPO_UNLEASHED }}
40+
version: ${{ vars.FIRMWARE_VERSION }}
41+
src-included: 1
42+
#- firmware: official
43+
# url: ${{ vars.REPO_OFFICIAL }}
44+
# version: "official"
45+
steps:
46+
- name: Set version
47+
env:
48+
INPUT_VERSION: ${{ inputs.version }}
49+
CURRENT_VERSION: ${{ env.CURRENT_VERSION }}
50+
shell: pwsh
51+
run: |
52+
$ReleaseVersion = ([string]::IsNullOrWhitespace($env:INPUT_VERSION) ? $env:CURRENT_VERSION : $env:INPUT_VERSION)
53+
Write-Output ('RELEASE_VERSION={0}' -f $ReleaseVersion) >> $env:GITHUB_ENV
54+
55+
- name: Copy Repo Files
56+
uses: actions/checkout@v3
57+
with:
58+
repository: "${{ matrix.url }}"
59+
clean: "true"
60+
submodules: "true"
61+
ref: "dev"
62+
63+
- name: Copy Repo Files
64+
if: ${{ matrix.src-included == 0 }}
65+
uses: actions/checkout@v3
66+
with:
67+
repository: "${{ vars.REPO_SELF }}"
68+
clean: "true"
69+
submodules: "true"
70+
path: "${{ env.IGNORED_PATH }}"
71+
72+
- name: Print vars about state or repo if Unleashed
73+
if: ${{ matrix.src-included == 1 }}
74+
shell: pwsh
75+
run: |
76+
git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1
77+
git submodule set-branch --branch master '${{ env.RELATIVE_PATH }}'
78+
git submodule sync '${{ env.RELATIVE_PATH }}'
79+
cd '${{ env.RELATIVE_PATH }}'
80+
if ( '${{ env.CURRENT_VERSION }}' -ne '${{ env.RELEASE_VERSION }}' ) {
81+
Write-Output '::warning title=Different version::Current version is ${{ env.CURRENT_VERSION }} but we trying to build ${{ env.RELEASE_VERSION }}'
82+
git checkout tags/v${{ env.RELEASE_VERSION }} -b tmp-build
83+
84+
if ( $LASTEXITCODE -ne 0 ) {
85+
Write-Error '::error title=Cannot checkout to this version::Error during execution checkout to this tag ${{ env.RELEASE_VERSION }}'
86+
exit 1
87+
}
88+
}
89+
90+
$Output = (git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1)
91+
92+
if ( $LASTEXITCODE -ne 0 ) {
93+
Write-Error '::error title=Invalid checkout::Invalid checkout'
94+
exit 1
95+
}
96+
Write-Output ('::notice title=Git output::{0}' -f $Output)
97+
98+
- name: Print vars about state or repo if Official
99+
if: ${{ matrix.src-included == 0 }}
100+
shell: pwsh
101+
run: |
102+
git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1
103+
cd '${{ env.IGNORED_PATH }}'
104+
105+
if ( '${{ env.CURRENT_VERSION }}' -ne '${{ env.RELEASE_VERSION }}' ) {
106+
Write-Output '::warning title=Different version::Current version is ${{ env.CURRENT_VERSION }} but we trying to build ${{ env.RELEASE_VERSION }}'
107+
git checkout tags/v${{ env.RELEASE_VERSION }} -b tmp-build
108+
109+
if ( $LASTEXITCODE -ne 0 ) {
110+
Write-Error '::error title=Cannot checkout to this version::Error during execution checkout to this tag ${{ env.RELEASE_VERSION }}'
111+
exit 1
112+
}
113+
} else {
114+
$Output = (git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1)
115+
116+
if ( $LASTEXITCODE -ne 0 ) {
117+
Write-Error '::error title=Invalid checkout::Invalid checkout'
118+
exit 1
119+
}
120+
Write-Output ('::notice title=Git output::{0}' -f $Output)
121+
}
122+
123+
# - name: Restore FBT
124+
# id: cache-restore
125+
# if: ${{ success() }}
126+
# uses: actions/cache/restore@v3
127+
# with:
128+
# path: |
129+
# build/**
130+
# debug/**
131+
# # An explicit key for restoring and saving the cache
132+
# key: 'fbt=${{ env.FIRMWARE_VERSION }}'
133+
#
134+
- name: Build Firmware
135+
shell: bash
136+
if: ${{ success() }}
137+
env:
138+
FBT_NO_SYNC: 0
139+
DIST_SUFFIX: ${{ matrix.version }}
140+
WORKFLOW_BRANCH_OR_TAG: release-cfw
141+
run: |
142+
./fbt COMPACT=1 DEBUG=0 fap_dist
143+
144+
# - name: Save FBT
145+
# id: cache-save
146+
# if: ${{ success() }}
147+
# uses: actions/cache/save@v3
148+
# with:
149+
# path: |
150+
# build/**
151+
# debug/**
152+
# # An explicit key for restoring and saving the cache
153+
# key: ${{ steps.cache-restore.outputs.cache-primary-key }}
154+
155+
- name: Create assets
156+
if: ${{ success() }}
157+
shell: pwsh
158+
env:
159+
ZIP_NAME: "SubGHz_Bruteforcer_${{ env.RELEASE_VERSION }}_${{ matrix.firmware }}.zip"
160+
TGZ_NAME: "SubGHz_Bruteforcer_${{ env.RELEASE_VERSION }}_${{ matrix.firmware }}.tgz"
161+
run: |
162+
function Format-Bytes {
163+
param(
164+
[int]$number
165+
)
166+
$sizes = 'KB', 'MB', 'GB', 'TB', 'PB'
167+
for ($x = 0; $x -lt $sizes.count; $x++) {
168+
if ($number -lt [int64]"1$($sizes[$x])") {
169+
if ($x -eq 0) {
170+
return "$number B"
171+
}
172+
else {
173+
$num = $number / [int64]"1$($sizes[$x-1])"
174+
$num = "{0:N2}" -f $num
175+
return "$num $($sizes[$x-1])"
176+
}
177+
}
178+
}
179+
}
180+
$ZipName = $env:ZIP_NAME
181+
$TgzName = $env:TGZ_NAME
182+
$FapNamme = 'SubGHz_Bruteforcer.fap'
183+
$DstFap = "./$FapNamme"
184+
185+
if (!(Test-Path -Path "dist/f7-C/apps/Sub-GHz/$FapNamme" -PathType Leaf)) {
186+
Write-Error '::error title=Files not found::Cannot find files in location'
187+
exit 1
188+
}
189+
190+
$Size = (Get-Item -Path "dist/f7-C/apps/Sub-GHz/$FapNamme" | Get-ItemPropertyValue -Name Length)
191+
Write-Output ('Filesize: {0}' -f (Format-Bytes $Size))
192+
Copy-Item -Force -Path "dist/f7-C/apps/Sub-GHz/$FapNamme" -Destination $DstFap
193+
194+
zip -r -qq $ZipName $DstFap
195+
tar zcf $TgzName $DstFap
196+
197+
if ( !(Test-Path -Path $ZipName -PathType Leaf) -or !(Test-Path -Path $TgzName -PathType Leaf) ) {
198+
Write-Error '::error title=Files not found::Cannot find files in location'
199+
exit 1
200+
}
201+
202+
$ZipSize = Format-Bytes (Get-Item -Path $ZipName).Length
203+
$TgzSize = Format-Bytes (Get-Item -Path $TgzName ).Length
204+
205+
Write-Output ('ZIP_NAME={0}' -f $ZipName) >> $env:GITHUB_ENV
206+
Write-Output ('TGZ_NAME={0}' -f $TgzName ) >> $env:GITHUB_ENV
207+
Write-Output ('ZIP_TAG={0} ({1})' -f $ZipName, $ZipSize) >> $env:GITHUB_ENV
208+
Write-Output ('TGZ_TAG={0} ({1})' -f $TgzName , $TgzSize) >> $env:GITHUB_ENV
209+
- name: Create assets
210+
if: ${{ success() && env.ZIP_NAME != '' }}
211+
env:
212+
GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }}
213+
run: |
214+
gh release upload 'v${{ env.RELEASE_VERSION }}' --clobber \
215+
'${{ env.ZIP_NAME }}#${{ env.ZIP_TAG }}' '${{ env.TGZ_NAME }}#${{ env.TGZ_TAG }}' -R ${{ env.REPO_SELF }}
216+
gh release edit 'v${{ env.RELEASE_VERSION }}' --draft=false -R ${{ env.REPO_SELF }}
217+
218+
#EOF

.github/workflows/version-check.yml

+169
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
name: "Version check for NEW release"
2+
run-name: " Version check for NEW release ${{ inputs.DEPLOY_TARGET }} by @${{ github.ACTOR }}"
3+
4+
on:
5+
workflow_dispatch:
6+
push:
7+
branches:
8+
- master
9+
schedule:
10+
- cron: "*/30 * * * *"
11+
12+
permissions:
13+
contents: write
14+
15+
jobs:
16+
pull-request:
17+
concurrency:
18+
group: check-for-new-versions
19+
cancel-in-progress: false
20+
runs-on: ubuntu-latest
21+
env:
22+
REPO_UNLEASHED: ${{ vars.REPO_UNLEASHED }}
23+
RELEASE_VERSION: ${{ vars.RELEASE_VERSION }}
24+
FIRMWARE_VERSION: ${{ vars.FIRMWARE_VERSION }}
25+
REPO_SELF: ${{ vars.REPO_SELF }}
26+
CHECKOUT_DIR: "firmware"
27+
steps:
28+
- name: Copy Repo Files
29+
uses: actions/checkout@v3
30+
with:
31+
repository: "${{ env.REPO_SELF }}"
32+
path: "${{ env.CHECKOUT_DIR }}"
33+
clean: "true"
34+
submodules: "true"
35+
token: ${{ secrets.FLIPPER_TOKEN }}
36+
- name: Check firmware release
37+
shell: pwsh
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
run: |
41+
function CleanInput
42+
{
43+
param(
44+
[string]
45+
$DurtyString
46+
)
47+
return $DurtyString -replace ('[^a-zA-Z\d_\-\,\.\t\n\r\:\;]', '')
48+
}
49+
50+
$Release = @(`
51+
(CleanInput `
52+
(gh release list -L 1 --repo '${{ env.REPO_UNLEASHED }}')`
53+
) -split "`t")
54+
55+
$FirmwareVersionNumber = 0
56+
$StoredFirmwareVersionNumber = 0
57+
if ($Release[2] -match '\-(\d+)$')
58+
{
59+
$FirmwareVersionNumber = [int]($Matches[1])
60+
}
61+
else
62+
{
63+
Write-Error ('::error title=Invalid firmware number::Error during execution this tags {0}' -f $FirmwareVersionNumber)
64+
exit 1
65+
}
66+
if ('${{ env.FIRMWARE_VERSION }}' -match '\-(\d+)$')
67+
{
68+
$StoredFirmwareVersionNumber = [int]($Matches[1])
69+
}
70+
else
71+
{
72+
Write-Error ('::error title=Invalid STORED firmware number::Error during execution this version {0}' -f '${{ env.FIRMWARE_VERSION }}')
73+
exit 1
74+
}
75+
76+
$LatestFirmware = CleanInput ((CleanInput (gh release list -L 1 --repo '${{ env.REPO_SELF }}') -replace '\t', ';') | `
77+
ConvertFrom-Csv -Delimiter ';' -Header name, flag, tag).tag
78+
79+
$Delta = ( [DateTime]::Now - [DateTime]::Parse($Release[3]) )
80+
$NewVersionFw = $false
81+
Write-Host ('Latest firmware {0}' -f $LatestFirmware) -ForegroundColor Gray -BackgroundColor Magenta
82+
Write-Debug ('::debug LatestFirmware {0}' -f $LatestFirmware)
83+
84+
Write-Output ('REMOTE_TAG_INFO=[{0}]({1}/releases/tag/{2})' -f $LatestFirmware, '${{ env.REPO_UNLEASHED }}', $LatestFirmware) >> $env:GITHUB_ENV
85+
if (($FirmwareVersionNumber -gt $StoredFirmwareVersionNumber) -and ( $Delta -gt [TimeSpan]::FromMinutes(10)))
86+
{
87+
Write-Debug ('::debug LatestFirmware {0}' -f $LatestFirmware)
88+
Write-Output ('FIRMWARE_VERSION={0}' -f $LatestFirmware) >> $env:GITHUB_ENV
89+
$NewVersionFw = $true
90+
}
91+
elseif ($FirmwareVersionNumber -lt $StoredFirmwareVersionNumber)
92+
{
93+
Write-Error ('::error title=Invalid check of stored::Version in repo: {0}, but we think it is {1}' -f $FirmwareVersionNumber, $StoredFirmwareVersionNumber)
94+
exit 1
95+
}
96+
97+
$LastPublished = (gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" '/repos/${{ vars.REPO_SELF }}/releases?per_page=1' | ConvertFrom-Json).published_at
98+
$Delta = ([DateTime]::Now - $LastPublished)
99+
100+
$Release = (gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" '/repos/${{ vars.REPO_SELF }}/tags?per_page=1' | ConvertFrom-Json).name
101+
Write-Host ('Release {0}' -f $Release) -ForegroundColor Gray -BackgroundColor Magenta
102+
$LatestTag = $Release.Substring(1)
103+
104+
$CurrentVersion = [version]::Parse('${{ env.RELEASE_VERSION }}')
105+
$ParsedRepoVersion = [version]::Parse($LatestTag)
106+
Write-Host ('Current tag:Repos tag {0}, {1}' -f $CurrentVersion, $ParsedRepoVersion) -ForegroundColor Gray -BackgroundColor Magenta
107+
Write-Debug ('::debug Current tag:Repos tag {0}, {1}' -f $CurrentVersion, $ParsedRepoVersion)
108+
if (($CurrentVersion -lt $ParsedRepoVersion) -and ( $Delta -gt [TimeSpan]::FromMinutes(10)))
109+
{
110+
$Tag = ('{0}.{1}.{2}' -f $ParsedRepoVersion.Major, $ParsedRepoVersion.Minor, $ParsedRepoVersion.Build)
111+
112+
Write-Output ('RELEASE_VERSION={0}' -f $Tag) >> $env:GITHUB_ENV
113+
Write-Output ('RELEASE_TYPE=2' -f $Tag) >> $env:GITHUB_ENV
114+
115+
Write-Output ('::warning title=New release!::Release {0}' -f $Tag)
116+
}
117+
elseif ( $NewVersionFw )
118+
{
119+
$Tag = ('{0}.{1}.{2}' -f $CurrentVersion.Major, $CurrentVersion.Minor, ($CurrentVersion.Build + 1))
120+
121+
Write-Output ('RELEASE_VERSION={0}' -f $Tag) >> $env:GITHUB_ENV
122+
Write-Output ('RELEASE_TYPE=1' -f $Tag) >> $env:GITHUB_ENV
123+
124+
Write-Output ('::warning title=Firmware was changed!::New version is {0}, creating release {1}' -f $LatestFirmware, $Tag)
125+
}
126+
elseif ( ($Delta -gt [TimeSpan]::FromMinutes(10)) -and ($CurrentVersion -gt $ParsedRepoVersion))
127+
{
128+
Write-Output ('::warning title=Invalid version!::Version in settings: {0}, but repo version is {1}. Going to change variable' -f $CurrentVersion, $ParsedRepoVersion)
129+
Write-Output ('RELEASE_VERSION={0}' -f $ParsedRepoVersion) >> $env:GITHUB_ENV
130+
Write-Output ('RELEASE_TYPE=3' -f $Tag) >> $env:GITHUB_ENV
131+
}
132+
else
133+
{
134+
# none to release
135+
Write-Host 'No new versions, sorry'
136+
}
137+
Write-Output ('CURRENT_TAG={0}' -f $LatestTag) >> $env:GITHUB_ENV
138+
139+
- name: Update Firmware variable and create UPDATE release if necessary
140+
if: ${{ success() && env.RELEASE_TYPE == 1 }}
141+
env:
142+
GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }}
143+
OWNER: ${{ github.repository_owner }}
144+
run: |
145+
gh release create 'v${{ env.RELEASE_VERSION }}' --latest --draft \
146+
--notes 'Rebuild with new version of firmware.\n\nSee: [CHANGELOG](${{ env.FIRMWARE_VERSION }}/blob/dev/CHANGELOG.md)\n${{ env.REMOTE_TAG_INFO}}' \
147+
--title 'Minor update v${{ env.RELEASE_VERSION }}' --verify-tag -R '${{ env.REPO_SELF }}'
148+
gh variable set FIRMWARE_VERSION -b '${{ env.FIRMWARE_VERSION }}' -R '${{ env.REPO_SELF }}'
149+
gh variable set RELEASE_VERSION -b '${{ env.RELEASE_VERSION }}' -R '${{ env.REPO_SELF }}'
150+
- name: Update release variable and create NEW release if necessary
151+
if: ${{ success() && env.RELEASE_TYPE == 2 }}
152+
env:
153+
GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }}
154+
OWNER: ${{ github.repository_owner }}
155+
run: |
156+
gh release create 'v${{ env.RELEASE_VERSION }}' --notes-start-tag 'v${{ env.CURRENT_TAG }}' --generate-notes --draft --latest \
157+
--notes 'New version is rolling out!' --verify-tag --title 'Release v${{ env.RELEASE_VERSION }}' -R '${{ env.REPO_SELF }}'
158+
159+
gh variable set FIRMWARE_VERSION -b '${{ env.FIRMWARE_VERSION }}' -R '${{ env.REPO_SELF }}'
160+
gh variable set RELEASE_VERSION -b '${{ env.RELEASE_VERSION }}' -R '${{ env.REPO_SELF }}'
161+
- name: Current settings in repo invalid. Changing
162+
if: ${{ success() && env.RELEASE_TYPE > 2 }}
163+
env:
164+
GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }}
165+
OWNER: ${{ github.repository_owner }}
166+
run: |
167+
gh variable set RELEASE_VERSION -b ${{ env.RELEASE_VERSION }} -R ${{ env.REPO_SELF }}
168+
169+
# EOF

0 commit comments

Comments
 (0)