From a92672e9db17e234770e50f369f4bc7c7c32e8ad Mon Sep 17 00:00:00 2001 From: honjow Date: Wed, 11 Oct 2023 11:05:56 +0800 Subject: [PATCH] add self-hosted ci --- .../build-system-image-self-hosted.yml | 60 ++++++++++++ .github/workflows/main-self-hosted.yml | 96 +++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 .github/workflows/build-system-image-self-hosted.yml create mode 100644 .github/workflows/main-self-hosted.yml diff --git a/.github/workflows/build-system-image-self-hosted.yml b/.github/workflows/build-system-image-self-hosted.yml new file mode 100644 index 000000000..25098274b --- /dev/null +++ b/.github/workflows/build-system-image-self-hosted.yml @@ -0,0 +1,60 @@ +name: Build ChimeraOS image self-hosted +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +on: + workflow_call: + inputs: + postfix: + type: string + description: Postfix used in release. + default: '' + +jobs: + build-system-image: + runs-on: self-hosted + permissions: + contents: write + outputs: + version: ${{ steps.build_image.outputs.version }} + display_name: ${{ steps.build_image.outputs.display_name }} + display_version: ${{ steps.build_image.outputs.display_version }} + image_filename: ${{ steps.build_image.outputs.image_filename }} + steps: + - uses: actions/checkout@v3 + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - uses: actions/download-artifact@v3 + with: + name: AUR-packages + path: aur-pkgs/ + - uses: actions/download-artifact@v3 + with: + name: Packages + path: pkgs/ + - name: Build system image + id: build_image + run: | + docker pull ${{ steps.meta.outputs.tags }} + docker run -u root --rm --entrypoint=/workdir/build-image.sh -v $(pwd):/workdir -v $(pwd)/output:/output -v $GITHUB_OUTPUT:$GITHUB_OUTPUT -e "GITHUB_OUTPUT=$GITHUB_OUTPUT" --privileged=true ${{ steps.meta.outputs.tags }} $(echo ${GITHUB_SHA} | cut -c1-7) + echo -e "$(docker inspect --format='{{index .RepoDigests 0}}' ${{ steps.meta.outputs.tags }})" > output/container.txt + - name: Create release + id: create_release + uses: softprops/action-gh-release@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + tag_name: ${{ steps.build_image.outputs.version }} + target_commitish: ${{ github.sha }} + name: ${{ steps.build_image.outputs.display_name }} ${{ steps.build_image.outputs.display_version }} ${{ inputs.postfix }} + draft: false + prerelease: true + fail_on_unmatched_files: true + files: | + output/${{ steps.build_image.outputs.image_filename }} + output/build_info.txt + output/sha256sum.txt + output/container.txt \ No newline at end of file diff --git a/.github/workflows/main-self-hosted.yml b/.github/workflows/main-self-hosted.yml new file mode 100644 index 000000000..7a2d928c4 --- /dev/null +++ b/.github/workflows/main-self-hosted.yml @@ -0,0 +1,96 @@ +name: System image build self-hosted + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +on: + push: + branches: + - master + - dev + workflow_dispatch: + +jobs: + build-docker-image: + name: Build and publish docker container + uses: ./.github/workflows/build-builder.yml + + list-pkgbuilds: + name: List Packages + runs-on: ubuntu-latest + outputs: + aur-pkgs: ${{ steps.set-aur-pkgs.outputs.matrix }} + pkgs: ${{ steps.set-pkgs.outputs.matrix }} + steps: + - uses: actions/checkout@v3 + - id: set-aur-pkgs + run: source ./manifest ; echo "matrix=$(echo ${AUR_PACKAGES} | jq -R -s -c 'split(" ")')" >> $GITHUB_OUTPUT + shell: bash + - id: set-pkgs + run: echo "matrix=$(ls -d pkgs/*/ | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT + shell: bash + + aur-pkgbuild: + needs: + - build-docker-image + - list-pkgbuilds + name: Build AUR package + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + package: ${{ fromJson(needs.list-pkgbuilds.outputs.aur-pkgs) }} + steps: + - uses: actions/checkout@v3 + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Build packages + run: | + docker pull ${{ steps.meta.outputs.tags }} + docker run --rm -v $(pwd):/workdir --entrypoint=/workdir/aur-pkgs/build-aur-package.sh ${{ steps.meta.outputs.tags }} ${{ matrix.package }} + - name: Upload Package Archives + uses: actions/upload-artifact@v3 + with: + name: AUR-packages + path: aur-pkgs/*.pkg.tar* + + pkgbuild: + needs: + - build-docker-image + - list-pkgbuilds + name: Build package + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + package: ${{ fromJson(needs.list-pkgbuilds.outputs.pkgs) }} + steps: + - uses: actions/checkout@v3 + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Build packages + run: | + docker pull ${{ steps.meta.outputs.tags }} + docker run --rm -v $(pwd):/workdir --entrypoint=/workdir/pkgs/build-package.sh ${{ steps.meta.outputs.tags }} ${{ matrix.package }} + - name: Upload Package Archives + uses: actions/upload-artifact@v3 + with: + name: Packages + path: pkgs/*.pkg.tar* + + build: + needs: + - build-docker-image + - aur-pkgbuild + - pkgbuild + name: Build ChimeraOS UNSTABLE image + uses: ./.github/workflows/build-system-image-self-hosted.yml + with: + postfix: "[UNSTABLE]" \ No newline at end of file