name: PikaOS Kernel Build And Release

on:
  workflow_dispatch

jobs:
  build:
    runs-on: self-hosted
    container:
      image: ghcr.io/pikaos-linux/pika-kernel-container@sha256:f48d8d6ea24049351f74133da4232634c3bcb2ffe66e0ff7e6f2692fdd33d25d
      volumes:
        - /proc:/proc
      options: --privileged -it

    steps:
    - uses: actions/checkout@v3
    
    - name: Import GPG key
      id: import_gpg
      uses: crazy-max/ghaction-import-gpg@v5
      with:
        gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
        passphrase: ${{ secrets.PASSPHRASE }}

    - name: Install SSH key
      uses: shimataro/ssh-key-action@v2
      with:
        key: ${{ secrets.SSH_KEY }}
        name: id_rsa
        known_hosts: ${{ secrets.KNOWN_HOSTS }}
        if_key_exists: replace
    
    - name: Build Kernel
      run: ./main.sh

    - name: Release Kernel
      run: ./release.sh

    - name: Purge cache
      uses: strrife/cloudflare-chunked-purge-action@master
      env:
        # Zone is required by both authentication methods
        CLOUDFLARE_ZONE: ${{ secrets.CLOUDFLARE_ZONE }}

        CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }}
        PURGE_URLS: ${{ vars.PURGE_URLS }}