Skip to content

Remove donation link. #135

Remove donation link.

Remove donation link. #135

name: publish docker image
on:
push:
branches:
- master
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install Nix
uses: cachix/install-nix-action@v27
- name: Attempt to Build Docker Image
id: build
run: |
set -e
docker build -t lurker:latest . || echo "BUILD_FAILED=true" >> $GITHUB_ENV
- name: Extract new hash from the error logs and update flake.nix
run: |
if [ "$BUILD_FAILED" == "true" ]; then
echo "Build failed. Attempting to extract new hash and update flake.nix..."
# Capture build log
BUILD_LOG=$(mktemp)
nix build .#dockerImage > "$BUILD_LOG" 2>&1 || true
# Display build log for debugging
echo "Build log:"
cat "$BUILD_LOG"
# Extract the new hash from the "got:" line in the log
NEW_HASH=$(grep -oP "got:\s+sha256-[a-zA-Z0-9+/=]+" "$BUILD_LOG" | awk '{print $2}' | head -n 1)
if [ -z "$NEW_HASH" ]; then
echo "Failed to retrieve new hash from logs."
exit 1
fi
echo "New hash extracted: $NEW_HASH"
# Use an alternative delimiter to avoid conflicts
sed -i "s|outputHash = \".*\";|outputHash = \"$NEW_HASH\";|" flake.nix
# Verify the change
echo "Updated flake.nix:"
grep outputHash flake.nix
# Commit the updated flake.nix
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
git add flake.nix
git commit -m "Update outputHash in flake.nix"
git push
# Mark that the flake was updated
echo "FLAKE_UPDATED=true" >> $GITHUB_ENV
else
echo "Build succeeded. Skipping flake update."
fi
- name: Retry Build
run: |
if [ "$FLAKE_UPDATED" == "true" ]; then
echo "Retrying build after flake update..."
docker build -t lurker:latest . || exit 1
else
echo "No flake update detected. Skipping retry."
fi
- name: Log in to Docker Hub
run: |
echo "Attempting to log in to Docker Hub..."
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
- name: Publish Docker Image
run: |
echo "Publishing Docker image..."
docker tag lurker:latest ${{ secrets.DOCKER_USERNAME }}/lurker:latest
docker push ${{ secrets.DOCKER_USERNAME }}/lurker:latest