Skip to content

Commit

Permalink
Merge pull request #3 from derskythe/feat/ci
Browse files Browse the repository at this point in the history
Feat/ci
  • Loading branch information
derskythe authored Mar 31, 2023
2 parents cd7d26e + f5fe40e commit 3ddc02f
Show file tree
Hide file tree
Showing 7 changed files with 281 additions and 125 deletions.
81 changes: 81 additions & 0 deletions .github/actions/make-release/action.yml
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 }}'
141 changes: 141 additions & 0 deletions .github/check-version.ps1
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
}
28 changes: 27 additions & 1 deletion .github/workflows/build-with-firmwware.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
required: false
type: string
release:
types: [unpublished]
types: [created]
push:
paths:
- .github/workflows/build-with-firmware.yml
Expand All @@ -30,6 +30,7 @@ jobs:
IGNORED_PATH: "applications_user/subbrute"
RELATIVE_PATH: "applications/external/subbrute"
CURRENT_VERSION: ${{ vars.RELEASE_VERSION }}
RELEASE_VERSION: ${{ vars.RELEASE_VERSION }}
strategy:
fail-fast: false
matrix:
Expand All @@ -39,6 +40,9 @@ jobs:
url: ${{ vars.REPO_UNLEASHED }}
version: ${{ vars.FIRMWARE_VERSION }}
src-included: 1
#- firmware: official
# url: ${{ vars.REPO_OFFICIAL }}
# version: "official"
steps:
- name: Set version
env:
Expand Down Expand Up @@ -117,6 +121,17 @@ jobs:
Write-Output ('::notice title=Git output::{0}' -f $Output)
}
# - name: Restore FBT
# id: cache-restore
# if: ${{ success() }}
# uses: actions/cache/restore@v3
# with:
# path: |
# build/**
# debug/**
# # An explicit key for restoring and saving the cache
# key: 'fbt=${{ env.FIRMWARE_VERSION }}'
#
- name: Build Firmware
shell: bash
if: ${{ success() }}
Expand All @@ -127,6 +142,17 @@ jobs:
run: |
./fbt COMPACT=1 DEBUG=0 fap_dist
# - name: Save FBT
# id: cache-save
# if: ${{ success() }}
# uses: actions/cache/save@v3
# with:
# path: |
# build/**
# debug/**
# # An explicit key for restoring and saving the cache
# key: ${{ steps.cache-restore.outputs.cache-primary-key }}

- name: Create assets
if: ${{ success() }}
shell: pwsh
Expand Down
Loading

0 comments on commit 3ddc02f

Please sign in to comment.