Small fixes #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Flow Main | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- v* | |
# Create a button to trigger the workflow manually. | |
workflow_dispatch: | |
env: | |
IMAGE_NAME: revive-adserver | |
jobs: | |
bump-version: | |
runs-on: ubuntu-latest | |
outputs: | |
VERSION: ${{ steps.version.outputs.VERSION }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set version | |
id: version | |
run: | | |
# 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//') | |
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT" | |
# Use Version `edge` tag convention | |
if [ "$VERSION" == "main" ] || [ "$VERSION" == "merge" ]; then | |
VERSION=edge | |
fi | |
# Update version in project | |
BUILD_TIMESTAMP=$(TZ=UTC date '+%Y-%m-%d %H:%M:%S %Z') | |
echo "{\"version\": \"$VERSION\", \"build\": \"$BUILD_TIMESTAMP\"}" > $GITHUB_WORKSPACE/www/version.json | |
- name: Upload version.json | |
uses: actions/upload-artifact@v2 | |
with: | |
name: version-json | |
path: www | |
docker-ci: | |
runs-on: ubuntu-latest | |
needs: [bump-version] | |
outputs: | |
IMAGE_TAG: ${{ steps.docker_push.outputs.IMAGE_TAG }} | |
steps: | |
- name: Download artifact version.json | |
uses: actions/download-artifact@v2 | |
with: | |
name: version-json | |
path: www | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Build Docker image | |
run: docker build . --file .docker/Dockerfile --tag $IMAGE_NAME | |
- name: Login into registry | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin | |
- name: Push Docker image | |
id: docker_push | |
env: | |
VERSION: ${{ needs.bump-version.outputs.VERSION }} | |
run: | | |
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME | |
# Use Docker `latest` tag convention | |
if [ "$VERSION" == "main" ] || [ "$VERSION" == "merge" ] || [ "$VERSION" == "edge" ]; then | |
VERSION="latest" | |
fi | |
# Change all uppercase to lowercase | |
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | |
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION | |
docker push $IMAGE_ID:$VERSION | |
echo "IMAGE_TAG=$VERSION" >> $GITHUB_OUTPUT | |
deploy: | |
runs-on: ubuntu-latest | |
needs: [bump-version, docker-ci] | |
steps: | |
- name: Deploy on K8s | |
id: deploy | |
env: | |
VERSION: ${{ needs.bump-version.outputs.VERSION }} | |
run: | | |
echo "Work in progress 🚀" | |
echo "For now, settle for the version ID: $VERSION" |