tdlight-telegram-bot-api/.github/workflows/docker.yml

67 lines
2.1 KiB
YAML
Raw Normal View History

name: Docker build and push
2020-11-06 01:42:25 +01:00
on:
push:
jobs:
build:
name: Build Docker image
2020-11-06 01:42:25 +01:00
runs-on: ubuntu-latest
env:
IMAGE_TAG: ghcr.io/${{ github.repository_owner }}/tdlightbotapi
2020-11-06 01:42:25 +01:00
steps:
- name: Checkout current repo
uses: actions/checkout@v2
with:
submodules: "recursive"
2020-11-06 01:42:25 +01:00
- name: Get version
2020-11-06 01:42:25 +01:00
run: |
# Get latest commit short hash
HASH_VERSION=$(git rev-parse --short HEAD)
2020-11-06 01:42:25 +01:00
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
# Convert IMAGE_TAG, HASH_VERSION and VERSION to lowercase (repository name must be lowercase)
IMAGE_TAG=$(echo "$IMAGE_TAG" | awk '{print tolower($0)}')
HASH_VERSION=$(echo "$HASH_VERSION" | awk '{print tolower($0)}')
VERSION=$(echo "$VERSION" | awk '{print tolower($0)}')
ARCH=${{ matrix.arch }}
SAFE_ARCH=${ARCH///} # linux/amd64 -> linuxamd64
2020-11-06 01:42:25 +01:00
# Store variable for future use
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
echo "HASH_VERSION=$HASH_VERSION" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "SAFE_ARCH=$SAFE_ARCH" >> $GITHUB_ENV
2020-11-06 01:42:25 +01:00
# Print debug info
echo "hash version: $HASH_VERSION"
echo "version: $VERSION"
echo "safe arch: $SAFE_ARCH"
# Save env to file
cat $GITHUB_ENV > github.env
- name: Login to ghcr registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GH_ACCESS_TOKEN }}
2020-11-06 01:42:25 +01:00
- name: Build and push image
2020-11-06 01:42:25 +01:00
run: |
docker build . -t ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}
docker push ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}