Skip to content

Commit

Permalink
chore(ci): Consolidate workflow into just commands (#1910)
Browse files Browse the repository at this point in the history
Signed-off-by: m2 <[email protected]>
Co-authored-by: Benjamin Sherman <[email protected]>
Co-authored-by: Jorge O. Castro <[email protected]>
Co-authored-by: befanyt <[email protected]>
  • Loading branch information
4 people authored Nov 10, 2024
1 parent af758c0 commit e1d7cf1
Show file tree
Hide file tree
Showing 20 changed files with 530 additions and 517 deletions.
19 changes: 14 additions & 5 deletions .github/changelogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,24 @@ def generate_changelog(
except Exception as e:
print(f"Failed to get finish hash:\n{e}")
finish = ""
try:
linux: str = next(iter(manifests.values()))["Labels"][
"ostree.linux"
]
start=linux.find(".fc") + 3
fedora_version=linux[start:start+2]
except Exception as e:
print(f"Failed to get linux version:\n{e}")
fedora_version = ""

# Remove .0 from curr
curr_pretty = re.sub(r"\.\d{1,2}$", "", curr)
# Remove target- from curr
curr_pretty = re.sub(rf"^[a-z]+-", "", curr_pretty)
pretty = target.capitalize() + " (F" + curr_pretty
if finish and target != "stable":
pretty += ", #" + finish[:7]
pretty += ")"
curr_pretty = re.sub(rf"^[a-z]+-|^[0-9]+-", "", curr_pretty)
pretty = target.capitalize()
pretty += " (F" + fedora_version
pretty += "." + curr_pretty
pretty += ", #" + finish[:7] + ")"

title = CHANGELOG_TITLE.format_map(defaultdict(str, tag=curr, pretty=pretty))

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/build-image-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ jobs:
generate-release:
name: Generate Release
needs: [build-image-beta]
if: github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call' || github.event_name.schedule == '40 4 * * 0'
secrets: inherit
uses: ./.github/workflows/generate-release.yml
with:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/build-image-gts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
paths-ignore:
- "**.md"
schedule:
- cron: "41 5 * * 0" # 5:41 UTC Weekly on Sundays
- cron: "45 5 * * 0" # 5:45 UTC Weekly on Sundays
workflow_dispatch:
workflow_call:

Expand All @@ -27,7 +27,6 @@ jobs:
generate_release:
name: Generate Release
needs: [build-image-gts]
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call'
secrets: inherit
uses: ./.github/workflows/generate-release.yml
with:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/build-image-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ jobs:
generate-release:
name: Generate Release
needs: [build-image-latest]
if: github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call' || github.event_name.schedule == '40 4 * * 0'
secrets: inherit
uses: ./.github/workflows/generate-release.yml
with:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/build-image-stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ jobs:
generate-release:
name: Generate Release
needs: [build-image-stable]
if: github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call' || github.event_name.schedule == '45 5 * * 0'
secrets: inherit
uses: ./.github/workflows/generate-release.yml
with:
Expand Down
28 changes: 19 additions & 9 deletions .github/workflows/generate-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,38 @@ jobs:
version: ${{ fromJson( inputs.stream_name ) }}

steps:
- name: Checkout last 500 commits (fot <commits> to work)
uses: actions/checkout@v4
- name: Checkout last 500 commits (for <commits> to work)
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 500

- name: Install Just
shell: bash
run: |
set -eoux pipefail
JUST_VERSION=$(curl -L https://api.github.com/repos/casey/just/releases/latest | jq -r '.tag_name')
curl -sSLO https://github.com/casey/just/releases/download/${JUST_VERSION}/just-${JUST_VERSION}-x86_64-unknown-linux-musl.tar.gz
tar -zxvf just-${JUST_VERSION}-x86_64-unknown-linux-musl.tar.gz -C /tmp just
sudo mv /tmp/just /usr/local/bin/just
rm -f just-${JUST_VERSION}-x86_64-unknown-linux-musl.tar.gz
- name: Check Just Syntax
shell: bash
run: |
just check
- name: Generate Release Text
id: generate-release-text
shell: bash
run: |
python3 ./.github/changelogs.py \
"${{ matrix.version }}" \
./output.env \
./changelog.md \
--workdir . \
--handwritten "${{ github.event.inputs.handwritten }}"
just changelogs "${{ matrix.version }}" "${{ github.event.inputs.handwritten }}"
source ./output.env
echo "title=${TITLE}" >> $GITHUB_OUTPUT
echo "tag=${TAG}" >> $GITHUB_OUTPUT
- name: Create Release
uses: softprops/action-gh-release@v2
if: contains(fromJson('["workflow_dispatch", "workflow_call"]'), github.event_name) || contains(fromJson('["45 5 * * 0", "40 4 * * 0"]'), github.event_name.schedule)
with:
name: ${{ steps.generate-release-text.outputs.title }}
tag_name: ${{ steps.generate-release-text.outputs.tag }}
Expand Down
125 changes: 22 additions & 103 deletions .github/workflows/reusable-build-iso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ concurrency:

jobs:
build-iso:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
Expand All @@ -34,132 +34,51 @@ jobs:
stream_name: ["${{ inputs.stream_name }}"]

steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1

- name: Checkout Repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- name: Matrix Variables
run: |
if [[ "${{ matrix.image_flavor }}" == "main" ]]; then
echo "IMAGE_NAME=${{ matrix.base_name }}" >> $GITHUB_ENV
else
echo "IMAGE_NAME=${{ format('{0}-{1}', matrix.base_name, matrix.image_flavor) }}" >> $GITHUB_ENV
fi
if [[ ${{ matrix.base_name }} =~ bluefin ]]; then
echo "VARIANT=Silverblue" >> $GITHUB_ENV
elif [[ ${{ matrix.base_name }} =~ aurora ]]; then
echo "VARIANT=Kinoite" >> $GITHUB_ENV
fi
- name: Get Current Fedora Version
id: labels
- name: Install Just
shell: bash
run: |
set -eo pipefail
kernel_release=$(skopeo inspect docker://ghcr.io/ublue-os/${{ env.IMAGE_NAME }}:${{ matrix.stream_name }} | jq -r '.Labels["ostree.linux"] | split(".x86_64")[0]')
fedora_version=$(echo $kernel_release | grep -oP 'fc\K[0-9]+')
echo "kernel_release=$kernel_release" >> $GITHUB_OUTPUT
echo "fedora_version=$fedora_version" >> $GITHUB_OUTPUT
- name: Set Image Tag
id: generate-tag
set -eoux pipefail
JUST_VERSION=$(curl -L https://api.github.com/repos/casey/just/releases/latest | jq -r '.tag_name')
curl -sSLO https://github.com/casey/just/releases/download/${JUST_VERSION}/just-${JUST_VERSION}-x86_64-unknown-linux-musl.tar.gz
tar -zxvf just-${JUST_VERSION}-x86_64-unknown-linux-musl.tar.gz -C /tmp just
sudo mv /tmp/just /usr/local/bin/just
rm -f just-${JUST_VERSION}-x86_64-unknown-linux-musl.tar.gz
- name: Check Just Syntax
shell: bash
run: |
TAG="${{ matrix.stream_name }}"
if [[ "${{ github.ref_name }}" == "testing" ]]; then
TAG="testing-${TAG}"
fi
# Would like to implement in the future. This will allow us to support image tags from a PR.
#if [[ github.event.number ]]; then
# TAG="pr-${{ github.event.number }}-${{ matrix.stream_name }}"
#fi
just check
echo "tag=${TAG}" >> $GITHUB_OUTPUT
- name: Set Flatpaks Directory Shortname
id: generate-flatpak-dir-shortname
shell: bash
run: |
if [[ "${{ env.IMAGE_NAME }}" =~ bluefin ]]; then
FLATPAK_DIR_SHORTNAME="bluefin_flatpaks"
elif [[ "${{ env.IMAGE_NAME }}" =~ aurora ]]; then
FLATPAK_DIR_SHORTNAME="aurora_flatpaks"
fi
echo "flatpak-dir-shortname=${FLATPAK_DIR_SHORTNAME}" >> $GITHUB_OUTPUT
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1

- name: Determine Flatpak Dependencies
id: flatpak_dependencies
- name: Build ISO
shell: bash
run: |
set -ex
image="ghcr.io/ublue-os/${{ env.IMAGE_NAME }}:${{ matrix.stream_name }}"
# Make temp space
TEMP_FLATPAK_INSTALL_DIR=$(mktemp -d -p ${{ github.workspace }} flatpak.XXX)
# Get list of refs from directory
FLATPAK_REFS_DIR=${{ github.workspace }}/${{ steps.generate-flatpak-dir-shortname.outputs.flatpak-dir-shortname }}
FLATPAK_REFS_DIR_LIST=$(cat ${FLATPAK_REFS_DIR}/* | tr '\n' ' ' )
DX_FLATPAK_REFS_DIR_LIST="$(cat dx_flatpaks/* | tr '\n' ' ' )"
if [[ ${{ env.IMAGE_NAME }} == *"-dx"* ]]; then
FLATPAK_REFS_DIR_LIST="${FLATPAK_REFS_DIR_LIST} ${DX_FLATPAK_REFS_DIR_LIST}"
fi
# Generate install script
cat << EOF > ${TEMP_FLATPAK_INSTALL_DIR}/script.sh
cat /temp_flatpak_install_dir/script.sh
mkdir -p /flatpak/flatpak /flatpak/triggers
mkdir /var/tmp || true
chmod -R 1777 /var/tmp
flatpak config --system --set languages "*"
flatpak remote-add --system flathub https://flathub.org/repo/flathub.flatpakrepo
flatpak install --system -y ${FLATPAK_REFS_DIR_LIST}
ostree refs --repo=\${FLATPAK_SYSTEM_DIR}/repo | grep '^deploy/' | grep -v 'org\.freedesktop\.Platform\.openh264' | sed 's/^deploy\///g' > /output/flatpaks_with_deps
EOF
docker run --rm --privileged \
--entrypoint bash \
-e FLATPAK_SYSTEM_DIR=/flatpak/flatpak \
-e FLATPAK_TRIGGERSDIR=/flatpak/triggers \
--volume ${FLATPAK_REFS_DIR}:/output \
--volume ${TEMP_FLATPAK_INSTALL_DIR}:/temp_flatpak_install_dir \
${image} /temp_flatpak_install_dir/script.sh
docker rmi ${image}
- name: Build ISOs
uses: jasonn3/build-container-installer@a1ce6da2d6c1af0561bec053366d0f3aa7e38743 # v1.2.3
id: build
with:
arch: x86_64
image_name: ${{ env.IMAGE_NAME }}
image_repo: ghcr.io/ublue-os
variant: ${{ env.VARIANT }}
version: ${{ steps.labels.outputs.fedora_version }}
image_tag: ${{ steps.generate-tag.outputs.tag }}
secure_boot_key_url: "https://github.com/ublue-os/akmods/raw/main/certs/public_key.der"
enrollment_password: "universalblue"
iso_name: ${{ env.IMAGE_NAME }}-${{ steps.generate-tag.outputs.tag }}.iso
enable_cache_dnf: "false"
enable_cache_skopeo: "false"
flatpak_remote_refs_dir: ${{ steps.generate-flatpak-dir-shortname.outputs.flatpak-dir-shortname }}
enable_flatpak_dependencies: "false"
image_name="$(just image_name ${{ matrix.base_name }} ${{ matrix.stream_name }} ${{ matrix.image_flavor }})"
sudo just build-iso-ghcr "${{ matrix.base_name }} ${{ matrix.stream_name }} ${{ matrix.image_flavor }}"
echo "IMAGE_NAME=${image_name}" >> $GITHUB_ENV
echo "ISO_BUILD_DIR=${{ github.workspace }}/${image_name}_build" >> $GITHUB_ENV
echo "ISO_NAME=${image_name}.iso" >> $GITHUB_ENV
- name: Move ISOs to Upload Directory
id: upload-directory
shell: bash
run: |
ISO_UPLOAD_DIR=${{ github.workspace }}/upload
mkdir ${ISO_UPLOAD_DIR}
mv ${{ steps.build.outputs.iso_path }}/${{ steps.build.outputs.iso_name }} ${ISO_UPLOAD_DIR}
mv ${{ steps.build.outputs.iso_path }}/${{ steps.build.outputs.iso_name }}-CHECKSUM ${ISO_UPLOAD_DIR}
mv ${{ env.ISO_BUILD_DIR }}/${{ env.ISO_NAME }} ${ISO_UPLOAD_DIR}
mv ${{ env.ISO_BUILD_DIR }}/${{ env.ISO_NAME }}-CHECKSUM ${ISO_UPLOAD_DIR}
echo "iso-upload-dir=${ISO_UPLOAD_DIR}" >> $GITHUB_OUTPUT
- name: Upload ISOs and Checksum to Job Artifacts
if: github.ref_name == 'testing'
#if: github.event_name == 'pull_request'
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4
with:
name: ${{ steps.build.outputs.iso_name }}
name: ${{ env.ISO_NAME }}
path: ${{ steps.upload-directory.outputs.iso-upload-dir }}
if-no-files-found: error
retention-days: 0
Expand Down
Loading

0 comments on commit e1d7cf1

Please sign in to comment.