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