-
Notifications
You must be signed in to change notification settings - Fork 1
release
This document provides a comprehensive overview of the GitHub Actions workflow defined in release.yaml. The workflow is designed to automate the release process of the AnasOS project. It triggers on pull requests merged into the main branch, determines the appropriate version increment based on the pull request title, creates a new release, and builds the project packages.
The release workflow is triggered when a pull request is closed and merged into the main branch. It performs the following key steps:
- Checks out the repository.
- Fetches the tags to determine the highest release version.
- Determines the version increment based on the pull request title.
- Creates a new release with the incremented version.
- Builds the project packages.
- Uploads the build artifacts to the release.
on:
pull_request:
branches: ["main"]
types: [closed]The workflow is triggered when a pull request targeting the main branch is closed.
permissions:
contents: write
pull-requests: readThe workflow requires write access to the repository contents and read access to pull requests.
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main'The create-release job runs only if the pull request is merged into the main branch.
- Checkout Repository
- name: Checkout with GitHub
uses: actions/checkout@v3Checks out the repository to the runner.
- Fetch Tags
- name: Fetch tags
run: git fetch --prune --unshallow --tagsFetches all tags to determine the highest release version.
- Get Highest Release Version
- name: Get highest release version
id: get_version
run: |
version=$(git tag --list 'v*' | sort -V | tail -n 1 || echo "v0.0.0")
echo "TAG=$version" >> $GITHUB_ENV
echo "Highest version is $version"Determines the highest release version tag.
- Determine Version Increment
- name: Determine version increment
id: determine_increment
run: |
major=$(echo "$TAG" | cut -d '.' -f1 | sed 's/v//')
minor=$(echo "$TAG" | cut -d '.' -f2)
patch=$(echo "$TAG" | cut -d '.' -f3)
pr_title="${{ github.event.pull_request.title }}"
if [[ "$pr_title" == *"[Major]"* ]]; then
major=$((major + 1))
minor=0
patch=0
elif [[ "$pr_title" == *"[Minor]"* ]]; then
minor=$((minor + 1))
patch=0
elif [[ "$pr_title" == *"[Patch]"* ]]; then
patch=$((patch + 1))
else
minor=$((minor + 1))
patch=0
fi
TAG="v$major.$minor.$patch"
echo "TAG=$TAG" >> $GITHUB_ENVDetermines the new version based on the pull request title. The version increment follows these rules:
- If the title contains
[Major], the major version is incremented, and the minor and patch versions are reset to 0. - If the title contains
[Minor], the minor version is incremented, and the patch version is reset to 0. - If the title contains
[Patch], the patch version is incremented. - If none of these keywords are present, the minor version is incremented, and the patch version is reset to 0.
- Create Release
- name: Create Release
id: release-action
uses: ncipollo/release-action@v1
with:
tag: ${{ env.TAG }}
name: Release ${{ env.TAG }}
commit: ${{ github.sha }}
body: ${{ github.event.pull_request.body }}Creates a new release with the determined version.
- Output Release URL File
- name: Output Release URL File
run: |
echo "${{ steps.release-action.outputs.upload_url }}" > release_url.txtWrites the release URL to a file for future use.
- Save Release URL File for Publish
- name: Save Release URL File for publish
uses: actions/upload-artifact@v4
with:
name: release_url
path: release_url.txtSaves the release URL file as an artifact.
needs: create-releaseThe build job depends on the successful completion of the create-release job.
- Checkout Repository
- name: Checkout with GitHub
uses: actions/checkout@v4Checks out the repository to the runner.
- Install Dependencies
- name: Install additional dependencies
run: |
sudo apt update
sudo apt install -y nasm grub-pc-bin grub-common make mtools xorriso
rustup update nightly
rustup target add x86_64-unknown-none --toolchain nightly
rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnuInstalls necessary dependencies for building the project.
- Build Project
- name: Build project
run: make no-runBuilds the project using the make command with the no-run argument, which generates the image file to be included in the release.
- Archive Build Output
- name: Archive build output
run: |
zip -r AnasOS.iso.zip AnasOS.isoThis step archives the build output into a zip file. Although the build output is a single ISO file, archiving it has several benefits:
- Compression: Reduces the file size, which can save storage space and reduce upload/download times.
- Compatibility: Some systems and tools handle zip files more gracefully than raw ISO files.
- Convenience: Packaging the file in a zip format can make it easier for users to manage and extract the contents if needed.
- Load Release URL File
- name: Load Release URL File from release job
id: download_release_info
uses: actions/download-artifact@v4
with:
name: release_urlDownloads the release URL file from the create-release job.
- Get Release File Name & Upload URL
- name: Get Release File Name & Upload URL
id: get_release_info
shell: bash
run: |
value=`cat "${{steps.download_release_info.outputs.download-path}}/release_url.txt"`
echo ::set-output name=upload_url::$valueExtracts the release upload URL from the file.
- Upload Release Asset
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get_release_info.outputs.upload_url }}
asset_path: AnasOS.iso.zip
asset_name: AnasOS.iso.zip
asset_content_type: application/zipUploads the build artifact to the release.
The release workflow for the AnasOS project automates the process of creating a new release and building the project packages. By leveraging GitHub Actions, the workflow ensures that every pull request merged into the main branch triggers a series of steps to determine the new version, create a release, and upload the build artifacts. This automation not only saves time but also reduces the potential for human error, ensuring a consistent and reliable release process.