65 lines
2.2 KiB
YAML
65 lines
2.2 KiB
YAML
name: Docker image (Gitea)
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
test:
|
|
name: Test and build
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Check out repository
|
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
|
|
with:
|
|
go-version-file: go.mod
|
|
cache: false
|
|
|
|
- name: Run tests
|
|
run: ./scripts/test.sh
|
|
|
|
- name: Build and run container smoke test
|
|
run: ./tests/container-smoke.sh
|
|
|
|
- name: Log in to Gitea Container Registry
|
|
if: gitea.event_name != 'pull_request'
|
|
env:
|
|
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
|
run: printf '%s' "$REGISTRY_TOKEN" | docker login git.ipao.vip --username "${{ gitea.actor }}" --password-stdin
|
|
|
|
- name: Publish tested image
|
|
if: gitea.event_name != 'pull_request'
|
|
env:
|
|
IMAGE_NAME: git.ipao.vip/rogee/mohomo-docker
|
|
SHA_TAG: sha-${{ gitea.sha }}
|
|
run: |
|
|
docker tag mohomo-docker:smoke "$IMAGE_NAME:latest"
|
|
docker tag mohomo-docker:smoke "$IMAGE_NAME:$SHA_TAG"
|
|
docker push "$IMAGE_NAME:latest"
|
|
docker push "$IMAGE_NAME:$SHA_TAG"
|
|
|
|
- name: Link package to repository
|
|
if: gitea.event_name != 'pull_request'
|
|
env:
|
|
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
|
run: |
|
|
package_api=https://git.ipao.vip/api/v1/packages/rogee/container/mohomo-docker
|
|
linked_repo="$(curl --fail --silent --show-error --header "Authorization: token $REGISTRY_TOKEN" "$package_api/-/latest" | jq -r '.repository.full_name // empty')"
|
|
if [ "$linked_repo" != rogee/mohomo-docker ]; then
|
|
curl --fail --silent --show-error --request POST \
|
|
--header "Authorization: token $REGISTRY_TOKEN" \
|
|
"$package_api/-/link/mohomo-docker"
|
|
fi
|
|
test "$(curl --fail --silent --show-error --header "Authorization: token $REGISTRY_TOKEN" "$package_api/-/latest" | jq -r '.repository.full_name // empty')" = rogee/mohomo-docker
|