Release #9
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
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@v4 | |
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/[email protected] | |
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@v4 | |
with: | |
ref: master | |
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@v2 | |
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@v4 | |
with: | |
ref: master | |
- name: Create Matrix | |
id: set-matrix | |
run: | | |
PY_INT=$(command -v python3) | |
CONFIG="${{ github.workspace }}/.github/workflow_config.yml" | |
GROUP="release" | |
$PY_INT ${{ github.workspace }}/.github/scripts/setup_matrix.py -c $CONFIG -g $GROUP --git | |
build: | |
needs: [release, matrix] | |
runs-on: ubuntu-latest | |
outputs: | |
base_name: ${{ steps.move-image.outputs.base_name }} | |
strategy: | |
fail-fast: false | |
matrix: | |
config: ${{ fromJson(needs.matrix.outputs.matrix) }} | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
with: | |
ref: master | |
path: repository | |
submodules: true | |
- name: Build image | |
id: build | |
uses: ./repository/.github/actions/build | |
with: | |
config: ${{ matrix.config }} | |
- name: Upload failed Logfile | |
if: failure() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: failed-${{ steps.move-image.outputs.image }}.log | |
path: repository/src/build.log | |
- name: Rename image file | |
id: move-image | |
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 }}" | |
mv repository/src/workspace/*.img $image.img | |
echo "base_name=${base_name}" >> $GITHUB_OUTPUT | |
echo "image=${image}" >> $GITHUB_OUTPUT | |
- 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.move-image.outputs.image }}.img || true | |
- 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.move-image.outputs.image }}.img.xz | |
- name: Calculating checksums | |
id: checksums | |
shell: bash | |
run: | | |
sha256sum ${{ steps.move-image.outputs.image }}.img > ${{ steps.move-image.outputs.image }}.img.sha256 | |
image_checksum=`cat ${{ steps.move-image.outputs.image }}.img.sha256 | awk '{ print $1 }'` | |
echo "image=${image_checksum}" >> $GITHUB_OUTPUT | |
sha256sum ${{ steps.move-image.outputs.image }}.img.xz > ${{ steps.move-image.outputs.image }}.img.xz.sha256 | |
zip_checksum=`cat ${{ steps.move-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.move-image.outputs.image }}.img.sha256;${{ steps.move-image.outputs.image }}.img.xz.sha256 | |
- name: Calculating filesizes | |
id: filesizes | |
shell: bash | |
run: | | |
image_filesize=`wc -c ${{ steps.move-image.outputs.image }}.img | awk '{print $1}'` | |
echo "image=${image_filesize}" >> $GITHUB_OUTPUT | |
zip_filesize=`wc -c ${{ steps.move-image.outputs.image }}.img.xz | awk '{print $1}'` | |
echo "zip=${zip_filesize}" >> $GITHUB_OUTPUT | |
- name: Debug output | |
run: | | |
echo "release-id: ${{ needs.release.outputs.id }}" | |
echo "release-version: ${{ needs.release.outputs.version }}" | |
echo "image-name: ${{ steps.move-image.outputs.image }}" | |
echo "checksum image: ${{ steps.checksums.outputs.image }}" | |
echo "checksum zip: ${{ steps.checksums.outputs.zip }}" | |
echo "filesize-image: ${{ steps.filesizes.outputs.image }}" | |
echo "filesize-zip: ${{ steps.filesizes.outputs.zip }}" | |
- name: Get JSON data | |
id: json-data | |
shell: bash | |
run: | | |
source repository/src/config | |
if [[ -n "${BASE_ARCH}" ]]; then | |
type="64-bit" | |
else | |
type="32-bit" | |
fi | |
name="${JSON_PRETTY_NAME} ${{ github.event.inputs.version }}" | |
name="${name} - ${JSON_PRETTY_SBC_NAME}" | |
name="${name} (${type})" | |
echo "pretty_name=${name}" >> $GITHUB_OUTPUT | |
echo "description=${JSON_DESCRIPTION}" >> $GITHUB_OUTPUT | |
echo "icon_url=${JSON_ICON_URL}" >> $GITHUB_OUTPUT | |
echo "init_format=${JSON_INIT_FORMAT}" >> $GITHUB_OUTPUT | |
echo "supported_sbc=${JSON_SUPPORTED_SBC}" >> $GITHUB_OUTPUT | |
- name: Generate JSON | |
id: json | |
uses: actions/github-script@v6 | |
env: | |
name: "${{ steps.json-data.outputs.pretty_name }}" | |
description: "${{ steps.json-data.outputs.description }}" | |
icon: "${{ steps.json-data.outputs.icon_url }}" | |
url: "https://github.com/${{ github.repository }}/releases/download/${{ github.event.inputs.version }}/${{ steps.move-image.outputs.image }}.img.xz" | |
extract_size: ${{ steps.filesizes.outputs.image }} | |
extract_sha256: "${{ steps.checksums.outputs.image }}" | |
image_download_size: ${{ steps.filesizes.outputs.zip }} | |
release_date: "${{ needs.release.outputs.date }}" | |
init_format: "${{ steps.json-data.outputs.init_format }}" | |
supported_sbc: ${{ steps.json-data.outputs.supported_sbc }} | |
with: | |
result-encoding: string | |
script: | | |
const fs = require('fs') | |
const { name, description, icon, url, extract_size, extract_sha256, image_download_size, release_date, init_format, supported_sbc } = process.env | |
const json = JSON.stringify({ | |
name, | |
description, | |
icon, | |
url, | |
extract_size: parseInt(extract_size), | |
extract_sha256, | |
image_download_size: parseInt(image_download_size), | |
release_date, | |
init_format, | |
devices: supported_sbc.split(" ").filter((item) => item != '') | |
}) | |
fs.writeFileSync("./${{ steps.move-image.outputs.image }}.json", json) | |
- name: Debug output | |
shell: bash | |
run: | | |
cat "./${{ steps.move-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.move-image.outputs.image }}.json | |
finish: | |
name: Finish Release | |
needs: [release, build] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Publish Release | |
uses: eregon/publish-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
release_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/[email protected] | |
with: | |
tag: ${{ github.event.inputs.version }} | |
fileName: "${{ needs.build.outputs.base_name }}-*.json" | |
out-file-path: "downloads" | |
- name: Combine JSON | |
id: json | |
uses: actions/github-script@v6 | |
with: | |
result-encoding: string | |
script: | | |
const downloadFolder = './downloads/' | |
const fs = require('fs') | |
const os_list = [] | |
fs.readdirSync(downloadFolder).forEach(file => { | |
const raw = fs.readFileSync('./downloads/' + file, {encoding:'utf8', flag:'r'}) | |
try { | |
os_list.push(JSON.parse(raw)) | |
} catch (err) { | |
console.log("Error parsing JSON string:", err) | |
} | |
}) | |
const json = JSON.stringify({os_list}) | |
fs.writeFileSync('rpi-imager.json', 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: rpi-imager.json | |
- name: Move in seperate dir | |
if: ${{ github.repository_owner == 'Mainsail-Crew' }} | |
run: | | |
mkdir upload | |
mv rpi-imager.json ./upload | |
- name: Upload to remote server | |
if: ${{ github.repository_owner == 'Mainsail-Crew' }} | |
uses: SamKirkland/[email protected] | |
with: | |
server: ${{ secrets.OSHOST }} | |
username: ${{ secrets.OSUSER }} | |
password: ${{ secrets.OSPASSWORD }} | |
local-dir: ./upload/ | |
update-changelog: | |
needs: finish | |
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: get_tags | |
shell: bash | |
run: | | |
echo "END_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))" >> $GITHUB_OUTPUT | |
if [[ "${{ github.repository_owner }}" == "Mainsail-Crew" ]]; then | |
echo "START_TAG=0.5.0" >> $GITHUB_OUTPUT | |
else | |
echo "START_TAG=$(git for-each-ref --sort=creatordate --count=1 --format='%(refname:lstrip=2)')" >> $GITHUB_OUTPUT | |
fi | |
- name: Generate a changelog | |
uses: orhun/git-cliff-action@v2 | |
id: git-cliff | |
with: | |
config: cliff.toml | |
args: ${{ steps.get_tags.outputs.START_TAG }}..${{ steps.get_tags.outputs.END_TAG }} | |
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 |