build-push-docker #10
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: build-push-docker | |
# Controls when the workflow will run | |
on: | |
# Triggers the workflow on push events for the master branch | |
push: | |
branches: [ master ] | |
paths: | |
- 'Dockerfile' | |
- '**.sh' | |
- '**.txt' | |
pull_request: | |
branches: [ master ] | |
paths: | |
- 'Dockerfile' | |
- '**.sh' | |
- '**.txt' | |
# Allows this workflow to be ran manually from the Actions tab | |
workflow_dispatch: | |
jobs: | |
build: | |
# The type of runner that the job will run on | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout repository | |
- uses: actions/[email protected] | |
- name: Set Timezone | |
uses: szenius/[email protected] | |
with: | |
timezoneLinux: "America/Chicago" | |
- name: Log in to Docker Hub | |
if: github.event_name != 'pull_request' | |
uses: docker/[email protected] | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
- name: Generate Version Number | |
run: | | |
eval "$(date +'today=%F now=%s')" | |
IMG_VER="$(date +%Y.%m.%d).$((now - $(date -d "$today 0" +%s)))" | |
echo "IMG_VER=${IMG_VER}" >> $GITHUB_ENV | |
BUILD_DATE=$(date +%Y.%m.%d) | |
echo "BUILD_DATE=${BUILD_DATE}" >> $GITHUB_ENV | |
- name: Docker Setup Buildx | |
uses: docker/[email protected] | |
- name: Build and push Docker images | |
uses: docker/[email protected] | |
with: | |
build-args: BUILD_DATE=${{ env.BUILD_DATE }} | |
context: . | |
pull: true | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: cubeworx/mcje-server:${{ env.IMG_VER }},cubeworx/mcje-server:latest | |
- name: Tweet Release | |
uses: nearform-actions/github-action-notify-twitter@master | |
if: github.event_name != 'pull_request' | |
with: | |
message: "New version of CubeWorx Minecraft Java Edition Server Image released: https://hub.docker.com/r/cubeworx/mcje-server/tags?page=1&ordering=last_updated&name=${{ env.IMG_VER }}" | |
twitter-app-key: ${{ secrets.TWITTER_CONSUMER_API_KEY }} | |
twitter-app-secret: ${{ secrets.TWITTER_CONSUMER_API_SECRET }} | |
twitter-access-token: ${{ secrets.TWITTER_ACCESS_TOKEN }} | |
twitter-access-token-secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} | |
- name: Create Tag | |
uses: mathieudutour/[email protected] | |
if: github.event_name != 'pull_request' | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
custom_tag: ${{ env.IMG_VER }} | |
- name: Create Release | |
uses: softprops/action-gh-release@v2 | |
if: github.event_name != 'pull_request' | |
with: | |
name: v${{ env.IMG_VER }} | |
generate_release_notes: true | |
tag_name: v${{ env.IMG_VER }} |