56 lines
1.5 KiB
YAML
56 lines
1.5 KiB
YAML
name: Build and Push
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
branches: [main]
|
|
|
|
env:
|
|
REGISTRY: forgejo.riotpiao.com
|
|
IMAGE_NAME: rock/poimen-memory
|
|
|
|
jobs:
|
|
test:
|
|
name: Test
|
|
runs-on: rust
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Run cargo build
|
|
run: cargo build --workspace
|
|
|
|
- name: Run cargo test
|
|
run: cargo test --all
|
|
|
|
build-image:
|
|
name: Build and Push Image
|
|
runs-on: rust
|
|
needs: test
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Build Docker image
|
|
run: |
|
|
docker build \
|
|
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \
|
|
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} \
|
|
-f Dockerfile .
|
|
|
|
echo "Built images:"
|
|
docker images | grep "${{ env.IMAGE_NAME }}"
|
|
|
|
- name: Login to registry and push
|
|
run: |
|
|
# Use Forgejo's actor token which has registry access
|
|
echo "${{ secrets.FORGEJO_TOKEN }}" | docker login ${{ env.REGISTRY }} \
|
|
-u ${{ github.actor }} --password-stdin
|
|
|
|
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
|
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
|
|
|
|
echo "Image pushed: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest"
|
|
env:
|
|
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|