Skip to content

Fix test workflows to line up with data. #4

Fix test workflows to line up with data.

Fix test workflows to line up with data. #4

Workflow file for this run

name: godir
on:
push:
branches:
- main
- master
paths:
- 'godir/**'
- '.github/workflows/godir.yml'
tags:
- 'godir/v*'
pull_request:
paths:
- 'godir/**'
- '.github/workflows/godir.yml'
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/godir
jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: godir
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.25'
cache-dependency-path: godir/go.sum
- name: Verify dependencies
run: go mod verify
- name: Run go vet
run: go vet ./...
- name: Run tests
run: go test -v ./...
build:
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/godir/v'))
outputs:
image_tag: ${{ steps.meta.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=match,pattern=godir/v(.*),group=1
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/godir/v') }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: godir
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
container-test:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull image
run: docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.build.outputs.image_tag }}
- name: Start container
run: |
docker run -d --name godir-test \
-p 8080:8080 \
-v ${{ github.workspace }}/perl_mongers.xml:/perl_mongers.xml:ro \
-e ROOT=/ \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.build.outputs.image_tag }}
sleep 3
- name: Test health endpoint
run: |
response=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/health)
if [ "$response" != "200" ]; then
echo "Health check failed with status $response"
docker logs godir-test
exit 1
fi
echo "Health check passed"
- name: Test redirect functionality
run: |
response=$(curl -s -o /dev/null -w "%{http_code}" -H "Host: ny.pm.org" http://localhost:8080/)
if [ "$response" != "301" ]; then
echo "Redirect test failed with status $response"
docker logs godir-test
exit 1
fi
echo "Redirect test passed"
- name: Test Gone functionality
run: |
response=$(curl -s -o /dev/null -w "%{http_code}" -H "Host: tokyo.pm.org" http://localhost:8080/)
if [ "$response" != "410" ]; then
echo "Gone test failed with status $response"
docker logs godir-test
exit 1
fi
echo "Gone test passed"
- name: Stop container
if: always()
run: docker stop godir-test || true
# Build preview images for PRs when labeled
build-preview:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'deploy-preview')
environment: preview
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push preview
uses: docker/build-push-action@v6
with:
context: godir
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pr-${{ github.event.pull_request.number }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Cleanup PR images when PR is closed
cleanup-preview:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && github.event.action == 'closed'
permissions:
packages: write
steps:
- name: Delete PR image
uses: actions/delete-package-versions@v5
with:
package-name: godir
package-type: container
delete-only-untagged-versions: false
min-versions-to-keep: 0
ignore-versions: '^(?!pr-${{ github.event.pull_request.number }}$).*$'
continue-on-error: true