name: ci
on:
    push:
        branches:
            - main

jobs:
    build_and_publish:
        runs-on: docker
        container:
            image: ghcr.io/catthehacker/ubuntu:runner-latest
        steps:
            - uses: actions/checkout@v4
            - uses: actions/setup-node@v4
            - run: npm install
            - run: sudo apt update && sudo apt install -y maven
            - run: npm run build-keycloak-theme
            - run: mv dist_keycloak/keycloak-theme-for-kc-all-other-versions.jar sr2-cloud-theme.jar
            - run: sha256sum sr2-cloud-theme.jar > sr2-cloud-theme.jar.sha256
            - run: |
               curl -H "Authorization: token ${{ secrets.PACKAGE_TOKEN }}" -X DELETE "https://guardianproject.dev/api/packages/sr2/generic/keycloak-theme-cloud/latest"
            - run: |
               curl -H "Authorization: token ${{ secrets.PACKAGE_TOKEN }}" -X PUT --upload-file sr2-cloud-theme.jar https://guardianproject.dev/api/packages/sr2/generic/keycloak-theme-cloud/latest/sr2-cloud-theme.jar
            - run: |
               curl -H "Authorization: token ${{ secrets.PACKAGE_TOKEN }}" -X PUT --upload-file sr2-cloud-theme.jar.sha256 https://guardianproject.dev/api/packages/sr2/generic/keycloak-theme-cloud/latest/sr2-cloud-theme.jar.sha256
