name: Build and push timelimit-server image on: schedule: - cron: "30 5 */3 * *" # every 72 hours workflow_dispatch: jobs: check: runs-on: ubuntu-latest outputs: exists: ${{ steps.exists.outputs.exists }} tag: ${{ steps.tag.outputs.tag }} steps: # Get latest timelimit-server tag - name: Get timelimit-server tag id: tag run: | LATEST_TAG=$(git ls-remote --tags --refs https://gitea.furb.it/${{ vars.SERVER_PATH }}.git | sort -t '/' -k 3 -V | tail -n 1 | cut -f2 | sed 's/refs\/tags\///') echo "tag=$LATEST_TAG" >> $GITEA_OUTPUT # Try to read timelimit-server tag from latest image label - name: Check if image with timelimit-server tag exists id: exists run: | TAG="${{ steps.tag.outputs.tag }}" STATUS=$(curl -s -o /dev/null -w "%{http_code}" \ -u "${{ secrets.USERNAME }}:${{ secrets.ACCESS_TOKEN }}" \ -H "Accept: application/vnd.docker.distribution.manifest.v2+json" \ https://gitea.furb.it/v2/${{ vars.SERVER_IMAGE }}/manifests/$TAG) if [ "$STATUS" = "200" ]; then echo "exists=true" >> $GITEA_OUTPUT else echo "exists=false" >> $GITEA_OUTPUT fi build: runs-on: ubuntu-latest needs: check if: needs.check.outputs.exists == 'false' steps: # Checkout timelimit-server repository for build - name: Checkout timelimit-server repository uses: actions/checkout@v4 with: repository: ${{ vars.SERVER_PATH }}.git ref: ${{ needs.check.outputs.tag }} token: ${{ secrets.ACCESS_TOKEN }} # Login to registry (needed to inspect latest image) - name: Docker login run: | echo "${{ secrets.ACCESS_TOKEN }}" | docker login gitea.furb.it \ -u "${{ secrets.USERNAME }}" \ --password-stdin # Build image with tag - name: Build Docker image run: | docker build \ -f Dockerfile \ --label timelimit-server.tag=${{ needs.check.outputs.tag }} \ -t gitea.furb.it/${{ vars.SERVER_IMAGE }}:${{ needs.check.outputs.tag }} \ -t gitea.furb.it/${{ vars.SERVER_IMAGE }}:latest \ . # Push images - name: Push Docker images run: | docker push gitea.furb.it/${{ vars.SERVER_IMAGE }}:${{ needs.check.outputs.tag }} docker push gitea.furb.it/${{ vars.SERVER_IMAGE }}:latest