mirror of
https://github.com/tdlight-team/tdlight-telegram-bot-api.git
synced 2024-12-25 20:25:51 +01:00
71 lines
2.0 KiB
YAML
71 lines
2.0 KiB
YAML
name: Docker Build + Image Push
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
pull_request:
|
|
|
|
|
|
jobs:
|
|
build:
|
|
name: Build Image
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_TAG: ghcr.io/tdlight-team/tdlightbotapi
|
|
|
|
steps:
|
|
- name: Checkout current repo
|
|
uses: actions/checkout@v2
|
|
with:
|
|
submodules: "recursive"
|
|
|
|
- name: Get version
|
|
run: |
|
|
# Get latest commit short hash
|
|
HASH_VERSION=$(git rev-parse --short HEAD)
|
|
|
|
# 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_ID and VERSION to lowercase (repository name must be lowercase)
|
|
IMAGE_ID=$(echo "$IMAGE_ID" | awk '{print tolower($0)}')
|
|
HASH_VERSION=$(echo "$HASH_VERSION" | awk '{print tolower($0)}')
|
|
VERSION=$(echo "$VERSION" | awk '{print tolower($0)}')
|
|
|
|
# Store variable for future use
|
|
echo "HASH_VERSION=$HASH_VERSION" >> $GITHUB_ENV
|
|
echo "VERSION=$VERSION" >> $GITHUB_ENV
|
|
|
|
# Print debug info
|
|
echo "hash version: $HASH_VERSION"
|
|
echo "version: $VERSION"
|
|
|
|
- name: Build image
|
|
run: |
|
|
docker build \
|
|
--cache-from $IMAGE_TAG:latest \
|
|
--tag $IMAGE_TAG:$HASH_VERSION \
|
|
--tag $IMAGE_TAG:$VERSION \
|
|
.
|
|
|
|
- name: Login to registry
|
|
run: |
|
|
echo "${{ secrets.GH_ACCESS_TOKEN }}" | docker login $REGISTRY -u ${{ github.actor }} --password-stdin
|
|
|
|
- name: Push images
|
|
run: |
|
|
docker push $IMAGE_TAG:$VERSION
|
|
docker push $IMAGE_TAG:$HASH_VERSION
|
|
|
|
- name: Logout from registry
|
|
run: |
|
|
docker logout $REGISTRY
|