Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(workflow): rework release workflow for multi builds #181

Merged
merged 40 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
614d64b
chore: WIP
meteyou Dec 11, 2022
fea8e83
chore: WIP
meteyou Dec 11, 2022
cc75909
chore: WIP
meteyou Dec 11, 2022
af061f3
chore: WIP
meteyou Dec 11, 2022
eecb3fa
chore: WIP
meteyou Dec 11, 2022
25e1ca6
chore: WIP
meteyou Dec 11, 2022
135f18c
chore: WIP
meteyou Dec 11, 2022
ab6e1fa
chore: WIP
meteyou Dec 11, 2022
75c0637
chore: WIP
meteyou Dec 11, 2022
dd05285
chore: WIP
meteyou Dec 11, 2022
baa9274
chore: add cliff-release.toml
meteyou Dec 11, 2022
13429cf
chore: WIP
meteyou Dec 11, 2022
2056108
chore: WIP
meteyou Dec 11, 2022
8832dc5
chore: WIP
meteyou Dec 11, 2022
a20738d
chore: WIP
meteyou Dec 11, 2022
ce70aab
chore: WIP
meteyou Dec 11, 2022
173d524
chore: WIP
meteyou Dec 11, 2022
096c51d
chore: WIP
meteyou Dec 11, 2022
c94e193
chore: WIP
meteyou Dec 11, 2022
0c5630e
chore: WIP
meteyou Dec 11, 2022
5b70afb
chore: WIP
meteyou Dec 11, 2022
73eeba7
chore: WIP
meteyou Dec 11, 2022
57cbd1e
chore: WIP
meteyou Dec 11, 2022
1ee4f9b
chore: WIP
meteyou Dec 11, 2022
ef672ce
chore: WIP
meteyou Dec 11, 2022
94bbafc
chore: WIP
meteyou Dec 11, 2022
7241069
chore: WIP
meteyou Dec 11, 2022
d2159a7
chore: WIP
meteyou Dec 11, 2022
6f48b83
chore: WIP
meteyou Dec 11, 2022
4375550
chore: WIP
meteyou Dec 11, 2022
970eb61
chore: WIP
meteyou Dec 11, 2022
befd469
chore: WIP
meteyou Dec 11, 2022
917356e
chore: WIP
meteyou Dec 11, 2022
6accbd8
chore: WIP
meteyou Dec 11, 2022
ef0bcec
chore: WIP
meteyou Dec 11, 2022
ab3314a
chore: WIP
meteyou Dec 11, 2022
8bd88d8
chore: WIP
meteyou Dec 11, 2022
2ea5fd9
chore: WIP
meteyou Dec 11, 2022
c3414cc
chore: remove old release workflow
meteyou Dec 12, 2022
c86b68a
chore: remove upload of uncompressed image
meteyou Dec 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/BuildImages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ on:
- "master"
- "develop"
paths:
- "src/**"
- "src/modules/**"
- "src/build_dist"
- "config/**"
- ".github/workflows/BuildImages.yml"
tags-ignore:
Expand Down
370 changes: 370 additions & 0 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,370 @@
name: Release

on:
workflow_dispatch:
inputs:
version:
type: string
description: New version number in X.Y.Z
required: true

jobs:
push-version-number:
name: Push version number
runs-on: ubuntu-latest
steps:
- name: Clone develop repository
uses: actions/checkout@v3
with:
token: ${{ secrets.PAT }}
ref: 'develop'

- name: Get current version
id: current-version
shell: bash
run: |
version=$(cat ./src/version)
echo "version=${version}" >> $GITHUB_OUTPUT

- name: Push version number
if: steps.current-version.outputs.version != github.event.inputs.version
shell: bash
run: |
echo ${{ github.event.inputs.version }} > ./src/version

- name: git add & commit & push
if: steps.current-version.outputs.version != github.event.inputs.version
uses: EndBug/add-and-commit@v9
with:
add: './src/version'
default_author: github_actions
message: 'chore: push version number to v${{ github.event.inputs.version }}'
push: true

update-master-branch:
name: Update master branch
needs: push-version-number
runs-on: ubuntu-latest
steps:
- uses: everlytic/branch-merge@1.1.5
with:
github_token: ${{ secrets.PAT }}
source_ref: 'develop'
target_branch: 'master'
commit_message_template: '[Automated] Merged {source_ref} into target {target_branch}'

release:
name: Create Release
needs: update-master-branch
runs-on: ubuntu-latest
outputs:
id: ${{ steps.create-release.outputs.id }}
date: ${{ steps.base-name.outputs.date }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: 'master'

- name: Get latest tag
id: latest_tag
shell: bash
run: |
echo "TAG_NAME=$(git describe --tags $(git rev-list --tags --max-count=1))" >> $GITHUB_OUTPUT

- name: Generate a changelog
uses: orhun/git-cliff-action@v1
id: changelog
with:
config: ./cliff-release.toml
args: ${{ steps.latest_tag.outputs.TAG_NAME }}..HEAD

- name: Create empty release
id: create-release
uses: softprops/action-gh-release@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: 'MainsailOS ${{ github.event.inputs.version }}'
tag_name: ${{ github.event.inputs.version }}
body: ${{ steps.changelog.outputs.content }}
draft: true

- name: Create Date
id: base-name
if: always()
shell: bash
run: |
NOW="$(date +"%Y-%m-%d")"
echo "date=${NOW}" >> $GITHUB_OUTPUT

matrix:
name: Create Matrix
needs: release
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: master

- name: Create Matrix
id: set-matrix
run: |
ARRAY=$(find ${{ github.workspace }}/config -type f -printf '%P\n' | sed '/default/d' | sort | jq -R -s -c 'split("\n")[:-1]')
echo "matrix=${ARRAY}" >> $GITHUB_OUTPUT

build:
needs: [ release, matrix ]
runs-on: ubuntu-latest
outputs:
base_name: ${{ steps.copy-image.outputs.base_name }}
strategy:
fail-fast: false
matrix:
config: ${{ fromJson(needs.matrix.outputs.matrix) }}
steps:
- name: Build image
id: build
uses: mainsail-crew/MainsailOS-actions/build-image@master
with:
config: ${{ matrix.config }}
build-ref: master

- name: Copy output
id: copy-image
if: always()
shell: bash
run: |
source repository/src/config
base_name="${{ needs.release.outputs.date }}-${DIST_NAME}-${DIST_VERSION}"
image="${base_name}-${{ steps.build.outputs.type }}-${{ steps.build.outputs.sbc }}"
cp repository/src/workspace/*.img $image.img

echo "base_name=${base_name}" >> $GITHUB_OUTPUT
echo "image=${image}" >> $GITHUB_OUTPUT

- name: Upload failed Logfile
if: failure()
uses: actions/upload-artifact@v3
with:
name: failed-${{ steps.copy-image.outputs.image }}.log
path: repository/src/build.log

- name: Debug output
run: echo ${{ steps.copy-image.outputs.image }}

- name: Compressing Image
shell: bash
run: |
CPU_COUNT="$(nproc)"
echo -e "\e[32mUsing ${CPU_COUNT} Cores for compression...\e[0m"
xz -efkvz9T"${CPU_COUNT}" ${{ steps.copy-image.outputs.image }}.img

- name: Upload Compressing Image
if: success()
uses: xresloader/upload-to-github-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ needs.release.outputs.id }}
file: ${{ steps.copy-image.outputs.image }}.img.xz

- name: Calculating checksums
id: checksums
shell: bash
run: |
sha256sum ${{ steps.copy-image.outputs.image }}.img > ${{ steps.copy-image.outputs.image }}.img.sha256
image_checksum=`cat ${{ steps.copy-image.outputs.image }}.img.sha256 | awk '{ print $1 }'`
echo "image=${image_checksum}" >> $GITHUB_OUTPUT

sha256sum ${{ steps.copy-image.outputs.image }}.img.xz > ${{ steps.copy-image.outputs.image }}.img.xz.sha256
zip_checksum=`cat ${{ steps.copy-image.outputs.image }}.img.xz.sha256 | awk '{ print $1 }'`
echo "zip=${zip_checksum}" >> $GITHUB_OUTPUT

- name: Upload Checksums
if: success()
uses: xresloader/upload-to-github-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ needs.release.outputs.id }}
file: ${{ steps.copy-image.outputs.image }}.img.sha256;${{ steps.copy-image.outputs.image }}.img.xz.sha256

- name: Calculating filesizes
id: filesizes
shell: bash
run: |
image_filesize=`wc -c ${{ steps.copy-image.outputs.image }}.img | awk '{print $1}'`
echo "image=${image_filesize}" >> $GITHUB_OUTPUT

zip_filesize=`wc -c ${{ steps.copy-image.outputs.image }}.img.xz | awk '{print $1}'`
echo "zip=${zip_filesize}" >> $GITHUB_OUTPUT

- name: Debug output
run: |
echo ${{ needs.release.outputs.id }}
echo ${{ needs.release.outputs.version }}

echo ${{ steps.copy-image.outputs.image }}

echo ${{ steps.checksums.outputs.image }}
echo ${{ steps.checksums.outputs.zip }}

echo ${{ steps.filesizes.outputs.image }}
echo ${{ steps.filesizes.outputs.zip }}

- name: Generate JSON
id: json
uses: actions/github-script@v6
env:
name: '"Mainsail OS ${{ github.event.inputs.version }}"'
description: '"Type: ${{ steps.build.outputs.type }}, SBC: ${{ steps.build.outputs.sbc }}"'
url: '"https://github.com/mainsail-crew/MainsailOS/releases/download/${{ github.event.inputs.version }}/${{ steps.copy-image.outputs.image }}.img.xz"'
icon: '"https://os.mainsail.xyz/rpi-imager.png"'
init_format: '"systemd"'
release_date: '"${{ needs.release.outputs.date }}"'
extract_size: ${{ steps.filesizes.outputs.image }}
extract_sha256: '"${{ steps.checksums.outputs.image }}"'
image_download_size: ${{ steps.filesizes.outputs.zip }}
image_download_sha256: '"${{ steps.checksums.outputs.zip }}"'
with:
result-encoding: string
script: |
const { name, description, url, icon, init_format, release_date, extract_size, extract_sha256, image_download_size, image_download_sha256 } = process.env

return JSON.stringify({
name,
description,
url,
icon,
init_format,
release_date,
extract_size,
extract_sha256,
image_download_size,
image_download_sha256
})

- name: Write JSON
run: echo "${{steps.json.outputs.result}}" > "./${{ steps.copy-image.outputs.image }}.json"

- name: Upload JSON
if: success()
uses: xresloader/upload-to-github-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ needs.release.outputs.id }}
file: ${{ steps.copy-image.outputs.image }}.json

finish:
name: Finish Release
needs: [ release, build ]
runs-on: ubuntu-latest
steps:
- name: Publish Release
uses: StuYarrow/publish-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
id: ${{ needs.release.outputs.id }}

update-rpi-imager:
name: Update rpi-imager json
needs: [ release, build, finish ]
runs-on: ubuntu-latest
steps:
- name: Download snipes
uses: robinraju/release-downloader@v1.6
with:
tag: ${{ github.event.inputs.version }}
fileName: "${{ needs.build.outputs.base_name }}-raspberry-*.json"
out-file-path: "downloads"

- name: Debug
run: |
ls ./downloads/*
touch rpi-imager.json

- name: setup python
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Run script
uses: jannekem/run-python-script-action@v1
with:
script: |
import os, json, shutil
with open("rpi-imager.json", "r+") as t:
t.truncate(0)
t.write('{ "os_list": [')
for filename in os.scandir('downloads'):
print(filename)
with open(filename, "r") as f:
content = f.read()
t.write(content)
t.write(',')
t.write('] }')
barak = open("rpi-imager.json", "r+")
contentb = barak.read()
print(contentb)

- name: Upload JSON
if: success()
uses: xresloader/upload-to-github-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ needs.release.outputs.id }}
file: rpi-imager.json

- name: Move in seperate dir
run: |
mkdir upload
mv rpi-imager.json ./upload

- name: Upload to remote server
uses: SamKirkland/FTP-Deploy-Action@4.3.3
with:
server: ${{ secrets.OSHOST }}
username: ${{ secrets.OSUSER }}
password: ${{ secrets.OSPASSWORD }}
local-dir: ./upload/

update-changelog:
needs: update-rpi-imager
name: Generate changelog
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: 'develop'
token: ${{ secrets.PAT }}
fetch-depth: 0

- name: Get latest tag
id: latest_tag
shell: bash
run: |
echo "TAG_NAME=$(git describe --tags $(git rev-list --tags --max-count=1))" >> $GITHUB_OUTPUT

- name: Generate a changelog
uses: orhun/git-cliff-action@v1
id: git-cliff
with:
config: cliff.toml
args: 0.5.0..${{ steps.latest_tag.outputs.TAG_NAME }}
env:
OUTPUT: ${{ github.workspace }}/CHANGELOG.md

- name: Show CHANGELOG
run: |
cat CHANGELOG.md
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 'docs(changelog): update changelog'
file_pattern: CHANGELOG.md
Loading