VyOS Autobuild Robot #239
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: VyOS Autobuild Robot | |
on: | |
schedule: | |
- cron: '00 04 * * *' | |
push: | |
branches: [ "main" ] | |
jobs: | |
check-release: | |
# Looks for the most recent release tag on the official vyos-build repo, and | |
# compares it to the most recently built version in this repo. | |
runs-on: ubuntu-latest | |
outputs: | |
build_new: ${{ steps.ver_check.outputs.build_new }} | |
curr_ver: ${{ steps.latest_rel.outputs.current }} | |
steps: | |
- name: Clone hcuk94/vyos-autobuild | |
uses: actions/checkout@v3 | |
- name: Clone vyos/vyos-build | |
run: | | |
cd ~ | |
git clone https://github.com/vyos/vyos-build.git | |
- name: Find latest release version | |
id: latest_rel | |
run: | | |
cd ~/vyos-build | |
currentVer=$(git describe --tags $(git rev-list --tags --max-count=1)) | |
echo "Current release determined as $currentVer" | |
echo "current=$currentVer" >> $GITHUB_OUTPUT | |
- name: Find previously built version | |
id: build_rel | |
run: | | |
prevVer=$(cat ~/work/vyos-autobuild/vyos-autobuild/release.txt) | |
echo "Previously built version determined as $prevVer" | |
echo "previous=$prevVer" >> $GITHUB_OUTPUT | |
- name: Compare versions | |
id: ver_check | |
run: | | |
if [[ ${{ steps.latest_rel.outputs.current }} != ${{ steps.build_rel.outputs.previous }} ]]; then | |
echo "Versions do not match, a new image will be built" | |
echo "build_new=true" >> $GITHUB_OUTPUT | |
else | |
echo "Versions match, we will not build" | |
echo "build_new=false" >> $GITHUB_OUTPUT | |
fi | |
map-version: | |
# VyOS' recommendation is to build from the active branch rather than the release tag; it will | |
# still be considered stable/LTS, but will include any recent bugfixes. | |
# This job maps version numbers to branch names, and must be manually updated as VyOS announce | |
# future versions. | |
runs-on: ubuntu-latest | |
needs: check-release | |
outputs: | |
vyos_branch: ${{ steps.set_output.outputs.branch_to_build }} | |
steps: | |
- name: Map 1.2.x to equuleus | |
if: startsWith(needs.check-release.outputs.curr_ver, '1.2.') | |
run: echo "BRANCH_TO_BUILD=crux" >> $GITHUB_ENV | |
- name: Map 1.3.x to equuleus | |
if: startsWith(needs.check-release.outputs.curr_ver, '1.3.') | |
run: echo "BRANCH_TO_BUILD=equuleus" >> $GITHUB_ENV | |
- name: Map 1.4.x to sagitta | |
if: startsWith(needs.check-release.outputs.curr_ver, '1.4.') | |
run: echo "BRANCH_TO_BUILD=sagitta" >> $GITHUB_ENV | |
- name: Set output variable | |
id: set_output | |
run: echo "branch_to_build=$BRANCH_TO_BUILD" >> $GITHUB_OUTPUT | |
build-iso: | |
# The main build job, which runs if the latest version doesn't match the previous build. | |
runs-on: ubuntu-latest | |
needs: [check-release, map-version] | |
permissions: | |
contents: write | |
if: needs.check-release.outputs.build_new == 'true' | |
steps: | |
- name: Initialise | |
run: echo "I will build version ${{ needs.check-release.outputs.curr_ver }} from the ${{ needs.map-version.outputs.vyos_branch }} branch" | |
- name: Clone vyos/vyos-build | |
run: | | |
cd ~ | |
git clone --depth 1 --single-branch --branch ${{ needs.map-version.outputs.vyos_branch }} https://github.com/vyos/vyos-build.git | |
- name: Build Image | |
run: | | |
cd ~/vyos-build | |
docker run --rm -i --privileged -v $(pwd):/vyos -w /vyos vyos/vyos-build:${{ needs.map-version.outputs.vyos_branch }} \ | |
/bin/bash -c "./configure --architecture amd64 --build-by '[email protected]' && sudo make iso" | |
- name: Create Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
token: "${{ secrets.GITHUB_TOKEN }}" | |
tag_name: "${{ needs.check-release.outputs.curr_ver }}" | |
prerelease: false | |
name: "Autobuild: ${{ needs.check-release.outputs.curr_ver }}" | |
files: | | |
../../../vyos-build/build/*.iso | |
update-release-file: | |
# This updates the release.txt file used to track the latest version built by this bot. | |
runs-on: ubuntu-latest | |
needs: [check-release, map-version, build-iso] | |
permissions: | |
contents: write | |
if: needs.check-release.outputs.build_new == 'true' | |
steps: | |
- name: Clone hcuk94/vyos-autobuild | |
uses: actions/checkout@v3 | |
- name: Update and commit last built version | |
run: | | |
echo ${{ needs.check-release.outputs.curr_ver }} > release.txt | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Actions" | |
git add release.txt | |
git commit -m "Update latest built version" | |
git push |