diff --git a/.gitea/workflows/publish.yml b/.gitea/workflows/publish.yml index bf79712..aab7756 100644 --- a/.gitea/workflows/publish.yml +++ b/.gitea/workflows/publish.yml @@ -3,16 +3,104 @@ on: push: branches: - master + paths: + - ".artixlinux/pkgbase.yaml" + +env: + CHECKOUT_ACTION: actions/checkout@v4 + PKGBASE_PARSER: https://git.sanin.dev/packages_infra/pkgbase-yaml-parser@v1 jobs: - build: + check-workflow: runs-on: ubuntu-latest - name: Build and publish + name: Check workflow permissions: contents: read steps: - - name: Build and publish - uses: https://git.sanin.dev/packages_test/build-publish@66e3c1910eb5043596a12331218780ea3e332240 + - name: Checkout + uses: ${{ env.CHECKOUT_ACTION }} + + - name: Retrieve latest + env: + WORKFLOW_URL: https://git.sanin.dev/packages_infra/package_template/raw/branch/master/.gitea/workflows/publish.yml + run: | + echo "Retrieving latest workflow from $WORKFLOW_URL" && \ + curl -f -o ".gitea/workflows/publish.yml" "$WORKFLOW_URL" + + - name: check for diff + run: git update-index --refresh + + build: + needs: check-workflow + runs-on: ubuntu-latest + name: Build and publish + permissions: + contents: write + steps: + - name: Checkout + uses: ${{ env.CHECKOUT_ACTION }} + + - name: Parse pkgbase + uses: ${{ env.PKGBASE_PARSER }} + id: parsed + with: + previous: ${{ gitea.server_url }}/${{ gitea.repository }}/raw/tag/latest/.artixlinux/pkgbase.yaml + current: .artixlinux/pkgbase.yaml + + - name: Move package + uses: ${{ env.PKGBASE_PARSER }} + if: ${{ steps.parsed.outputs.move == 'true' }} + with: + mode: move + parsed-data: ${{ steps.parsed.outputs.parsed-data }} + username: "${{ secrets.USERNAME }}" + token: ${{ secrets.TOKEN }} + + - name: Create publish script + shell: bash + if: ${{ steps.parsed.outputs.build == 'true' }} + run: | + echo "#!/bin/bash + echo '📤️ Uploading package to ${{ gitea.server_url }} ...' + for f in ./*.tar.zst; do + [ -f \"\$f\" ] || continue + curl -f --user \"\$username:\$token\" \ + --upload-file \"\$f\" \ + '${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/arch/${{ steps.parsed.outputs.destination }}' + done + " > "./post-entrypoint.sh" + chmod +x "./post-entrypoint.sh" + git config --global user.name 'Guy Incognito' + git config --global user.email 'user@local' + git add "./post-entrypoint.sh" && \ + git commit -m "persist publish script" && \ + cat "./post-entrypoint.sh" + + - name: Build package + uses: ${{ gitea.server_url }}/${{ gitea.repository_owner }}/build-publish/@build + if: ${{ steps.parsed.outputs.build == 'true' }} with: username: "${{ secrets.USERNAME }}" - token: "${{ secrets.TOKEN }}" + token: ${{ secrets.TOKEN }} + + - name: Revert publish script + shell: bash + if: ${{ steps.parsed.outputs.build == 'true' }} + run: git reset --hard HEAD~1 + + - name: Delete package + uses: ${{ env.PKGBASE_PARSER }} + if: ${{ steps.parsed.outputs.delete == 'true' }} + with: + mode: delete + parsed-data: ${{ steps.parsed.outputs.parsed-data }} + username: "${{ secrets.USERNAME }}" + token: ${{ secrets.TOKEN }} + + - name: Update latest tag + shell: bash + run: | + git config user.name "Gitea CI" + git config user.email "ci@gitea.local" + git tag -f latest + git push origin -f latest