forked from flipperdevices/flipperzero-firmware
-
-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from derskythe/feat/ci
Feat/ci
- Loading branch information
Showing
7 changed files
with
281 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
--- | ||
name: "Action release" | ||
description: "Steps to build release" | ||
author: "DerSkythe" | ||
|
||
inputs: | ||
release_type: | ||
description: 'release_type' | ||
required: true | ||
release_version: | ||
description: 'release_version' | ||
required: true | ||
firmware_version: | ||
description: 'firmware_version' | ||
required: true | ||
repo_self: | ||
description: 'REPO_SELF' | ||
required: true | ||
gh_token: | ||
description: 'github_gh_token' | ||
required: true | ||
owner: | ||
description: 'owner' | ||
required: true | ||
current_tag: | ||
description: 'current_tag' | ||
required: true | ||
remote_tag_info: | ||
description: 'remote_tag_info' | ||
required: true | ||
|
||
# outputs: | ||
# make-minor-release: | ||
# description: "make-minor-release" | ||
# value: ${{ steps.make-minor-release.outputs }} | ||
# make-major-release: | ||
# description: "make-minor-release" | ||
# value: ${{ steps.make-major-release.outputs }} | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Minor release | ||
if: ${{ inputs.release_type == 2 }} | ||
id: make-minor-release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
tag_name: 'v${{ inputs.release_version }}' | ||
name: 'Minor update v${{ inputs.release_version }}' | ||
token: ${{ inputs.gh_token }} | ||
draft: true | ||
generate_release_notes: true | ||
#target_commitish: ${{ github.SHA }} | ||
append_body: true | ||
body: 'Rebuild with new version of firmware.\n\nSee: [CHANGELOG](${{ inputs.firmware_version }}/blob/dev/CHANGELOG.md)\n${{ inputs.remote_tag_info }}' | ||
repository: '${{ inputs.repo_self }}' | ||
|
||
- name: Major release | ||
if: ${{ inputs.release_type == 1 }} | ||
id: make-major-release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
tag_name: 'v${{ inputs.release_version }}' | ||
name: Release v${{ inputs.release_version }} | ||
token: ${{ inputs.gh_token }} | ||
draft: true | ||
generate_release_notes: true | ||
#target_commitish: ${{ github.SHA }} | ||
append_body: true | ||
body: 'New version is rolling out!' | ||
repository: '${{ inputs.repo_self }}' | ||
|
||
- name: Update Firmware variable and create UPDATE release if necessary | ||
if: ${{ success() }} | ||
env: | ||
GITHUB_TOKEN: ${{ inputs.gh_token }} | ||
OWNER: ${{ inputs.owner }} | ||
shell: bash | ||
run: | | ||
gh variable set FIRMWARE_VERSION -b '${{ inputs.firmware_version }}' -R '${{ inputs.repo_self }}' | ||
gh variable set RELEASE_VERSION -b '${{ inputs.release_version }}' -R '${{ inputs.repo_self }}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
######################################## | ||
Set-StrictMode -Version 3.0 # | ||
$ErrorActionPreference = "Stop" # | ||
######################################## | ||
|
||
[string]$FirmwareVersion = $args[0] | ||
[string]$ReleaseVersion = $args[1] | ||
[string]$RepoSelf = $args[2] | ||
[string]$RepoUnleashed = $args[3] | ||
[bool]$ForGithubActions = $true | ||
|
||
################################################################################################################################ | ||
function CleanInput | ||
{ | ||
param( | ||
[string] | ||
$DurtyString | ||
) | ||
return $DurtyString -replace ('[^a-zA-Z\d_\-\,\.\t\n\r\:\;]', '') | ||
} | ||
|
||
################################################################################################################################ | ||
|
||
$Output = @{ | ||
RELEASE_VERSION = $ReleaseVersion | ||
CURRENT_TAG = $FirmwareVersion | ||
REMOTE_TAG_INFO = $FirmwareVersion | ||
RELEASE_TYPE = 0 | ||
} | ||
|
||
$Release = @(` | ||
(CleanInput ` | ||
(gh release list -L 1 --repo $RepoUnleashed)` | ||
) -split "`t") | ||
|
||
$FirmwareVersionNumber = 0 | ||
$StoredFirmwareVersionNumber = 0 | ||
$LatestFirmware = $Release[2] | ||
if ($Release[2] -match '\-(\d+)$') | ||
{ | ||
$FirmwareVersionNumber = [int]($Matches[1]) | ||
} | ||
else | ||
{ | ||
Write-Error ('::error title=Invalid firmware number::Error during execution this tags {0}' -f $FirmwareVersionNumber) | ||
exit 1 | ||
} | ||
if ($FirmwareVersion -match '\-(\d+)$') | ||
{ | ||
$StoredFirmwareVersionNumber = [int]($Matches[1]) | ||
} | ||
else | ||
{ | ||
Write-Error ('::error title=Invalid STORED firmware number::Error during execution this version {0}' -f $FirmwareVersion) | ||
exit 1 | ||
} | ||
$Delta = ( [DateTime]::Now - [DateTime]::Parse($Release[3])) | ||
Write-Host "FirmwareVersionNumber: $FirmwareVersionNumber, Delta: $Delta" | ||
#exit 0 | ||
|
||
$NewVersionFw = $false | ||
Write-Host ('Latest firmware {0}' -f $FirmwareVersionNumber) | ||
|
||
$Output.REMOTE_TAG_INFO = Write-Host ('[{0}]({1}/releases/tag/{2})' ` | ||
-f $LatestFirmware, $RepoUnleashed, $LatestFirmware) | ||
if (($FirmwareVersionNumber -gt $StoredFirmwareVersionNumber) -and ( $Delta -gt [TimeSpan]::FromMinutes(10))) | ||
{ | ||
$Output.REMOTE_TAG_INFO = $LatestFirmware | ||
$NewVersionFw = $true | ||
} | ||
elseif ($FirmwareVersionNumber -lt $StoredFirmwareVersionNumber) | ||
{ | ||
Write-Error ('::error title=Invalid check of stored::Version in repo: {0}, but we think it is {1}' ` | ||
-f $FirmwareVersionNumber, $StoredFirmwareVersionNumber) | ||
exit 1 | ||
} | ||
|
||
$PublishDates = (gh api -H "Accept: application/vnd.github+json" ` | ||
-H "X-GitHub-Api-Version: 2022-11-28" "/repos/$( $RepoSelf )/releases?per_page=1" ` | ||
| ConvertFrom-Json | Select-Object published_at, created_at) | ||
$LastPublished = ($null -eq $PublishDates.published_at ? $PublishDates.created_at : $PublishDates.published_at) | ||
$Delta = ([DateTime]::Now - $LastPublished) | ||
|
||
$Release = (gh api -H "Accept: application/vnd.github+json" ` | ||
-H "X-GitHub-Api-Version: 2022-11-28" "/repos/$( $RepoSelf )/tags?per_page=1" ` | ||
| ConvertFrom-Json).name | ||
Write-Host ('Release {0}' -f $Release) -ForegroundColor Gray -BackgroundColor Blue | ||
$LatestTag = $Release.Substring(1) | ||
|
||
$CurrentVersion = [version]::Parse($ReleaseVersion) | ||
$ParsedRepoVersion = [version]::Parse($LatestTag) | ||
|
||
Write-Host ('Current tag:Repos tag {0}, {1}' -f $CurrentVersion, $ParsedRepoVersion) ` | ||
-ForegroundColor Gray -BackgroundColor Blue | ||
Write-Debug ('::debug Current tag:Repos tag {0}, {1}' -f $CurrentVersion, $ParsedRepoVersion) | ||
|
||
if (($CurrentVersion -lt $ParsedRepoVersion) -and ( $Delta -gt [TimeSpan]::FromMinutes(10))) | ||
{ | ||
$Tag = ('{0}.{1}.{2}' -f $ParsedRepoVersion.Major, $ParsedRepoVersion.Minor, $ParsedRepoVersion.Build) | ||
|
||
$Output.RELEASE_VERSION = $Tag | ||
$Output.RELEASE_TYPE = 2 | ||
|
||
Write-Host ('::warning title=New release!::Release {0}' -f $Tag) | ||
} | ||
elseif ( $NewVersionFw ) | ||
{ | ||
$Tag = ('{0}.{1}.{2}' -f $CurrentVersion.Major, $CurrentVersion.Minor, ($CurrentVersion.Build + 1)) | ||
|
||
$Output.RELEASE_VERSION = $Tag | ||
$Output.RELEASE_TYPE = 1 | ||
|
||
Write-Host ('::warning title=Firmware was changed!::New version is {0}, need to create release {1}' -f $LatestFirmware, $Tag) | ||
} | ||
elseif ( ($Delta -gt [TimeSpan]::FromMinutes(10)) -and ($CurrentVersion -gt $ParsedRepoVersion)) | ||
{ | ||
Write-Host ('::warning title=Invalid version!::Version in settings: {0}, but repo version is {1}. Going to change variable' ` | ||
-f $CurrentVersion, $ParsedRepoVersion) | ||
|
||
$Output.RELEASE_VERSION = $ParsedRepoVersion | ||
$Output.RELEASE_TYPE = 3 | ||
} | ||
else | ||
{ | ||
# none to release | ||
Write-Host 'No new versions, sorry' | ||
} | ||
|
||
$Output.CURRENT_TAG = $LatestTag | ||
|
||
if($ForGithubActions) { | ||
$Plain = New-Object -TypeName "System.Text.StringBuilder"; | ||
$Output.GetEnumerator() | ForEach-Object { | ||
[void]$Plain.Append($_.Key) | ||
[void]$Plain.Append('=') | ||
[void]$Plain.AppendLine($_.Value) | ||
} | ||
Write-Output $Plain.ToString() | ||
} else { | ||
$Output | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.