Skip to content
This repository was archived by the owner on Jul 12, 2025. It is now read-only.

Build OS Image

Build OS Image #31

Workflow file for this run

name: Build OS Image
on:
schedule:
- cron: '0 0 */14 * *' # Every 2 weeks
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Important: get full history for merge-base
- name: Check for new commits
id: check-commits
run: |
# Get the latest release tag
LATEST_TAG=$(curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.UPLOAD_TOKEN }}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name)
# If no releases exist yet, we should proceed
if [ "$LATEST_TAG" = "null" ]; then
echo "No previous releases found - proceeding with build"
echo "has_new_commits=true" >> $GITHUB_OUTPUT
exit 0
fi
# Check if there are any commits since the last release
COMMITS_SINCE_LAST_RELEASE=$(git log $LATEST_TAG..HEAD --oneline | wc -l)
if [ "$COMMITS_SINCE_LAST_RELEASE" -gt 0 ]; then
echo "Found $COMMITS_SINCE_LAST_RELEASE new commits since last release - proceeding with build"
echo "has_new_commits=true" >> $GITHUB_OUTPUT
else
echo "No new commits since last release $LATEST_TAG - skipping build"
echo "has_new_commits=false" >> $GITHUB_OUTPUT
fi
- name: Install dependencies
if: steps.check-commits.outputs.has_new_commits == 'true'
run: |
sudo apt update
sudo apt install -y nasm
- name: Get latest release and compute next version
if: steps.check-commits.outputs.has_new_commits == 'true'
id: version
run: |
LATEST=$(curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.UPLOAD_TOKEN }}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name)
echo "Latest release tag: $LATEST"
if [[ "$LATEST" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
PATCH="${BASH_REMATCH[3]}"
else
MAJOR=0; MINOR=0; PATCH=0
fi
PATCH=$((PATCH + 1))
if [ $PATCH -ge 10 ]; then
PATCH=0
MINOR=$((MINOR + 1))
fi
if [ $MINOR -ge 10 ]; then
MINOR=0
MAJOR=$((MAJOR + 1))
fi
VERSION="v${MAJOR}.${MINOR}.${PATCH}"
NAME="CopperOS - ${VERSION}"
echo "Next version: $VERSION"
echo "tag_name=$VERSION" >> $GITHUB_OUTPUT
echo "version_name=$NAME" >> $GITHUB_OUTPUT
- name: Build OS image
if: steps.check-commits.outputs.has_new_commits == 'true'
run: |
nasm -f bin boot.asm -o boot.bin
nasm -f bin boot32.asm -o boot32.bin
nasm -f bin boot64.asm -o boot64.bin
nasm -f bin second_stage.asm -o second_stage.bin
gcc -ffreestanding -mcmodel=large -mno-red-zone -m64 -c kernel.c -o kernel.o -fno-pie -no-pie
ld -T linker.ld -nostdlib kernel.o -o kernel.bin
cat boot.bin second_stage.bin boot32.bin boot64.bin kernel.bin > os_image.bin
- name: Github Actions Create Release
if: steps.check-commits.outputs.has_new_commits == 'true'
uses: idev-coder/github-actions-release@v1.0.0
with:
github_token: ${{ secrets.UPLOAD_TOKEN }}
tag: ${{ steps.version.outputs.tag_name }}
body: "Release made by GitHub Actions..."
name: ${{ steps.version.outputs.version_name }}
env:
RELEASE_TOKEN: ${{ secrets.UPLOAD_TOKEN }}
- name: Publish Release Assets
if: steps.check-commits.outputs.has_new_commits == 'true'
uses: vinayaja/publish-release-assets@v1.1.0
with:
gh-token: ${{ secrets.UPLOAD_TOKEN }}
release-tag: ${{ steps.version.outputs.tag_name }}
asset-names: "os_image.bin"
overwrite: false
- uses: sarisia/actions-status-discord@v1
if: steps.check-commits.outputs.has_new_commits == 'true'
with:
webhook: ${{ secrets.COPPEROS_WEBHOOK_URL }}
status: ${{ job.status }}
content: "Hey @everyone! New Release!"
title: "Build New Release"
description: "`CopperOS ${{ steps.version.outputs.tag_name }}` available [Here](https://github.com/NightForge-Development/CopperOS/releases/tag/${{ steps.version.outputs.tag_name }})!"
image: "https://raw.githubusercontent.com/NightForge-Development/CopperOS/refs/heads/stable/check-mark.png"
color: 16749824
url: "https://github.com/NightForge-Development/CopperOS/releases/tag/${{ steps.version.outputs.tag_name }}"
username: CopperOS Releases
avatar_url: ${{ secrets.AVATAR_URL }}