get in touch #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: Docker Image Push | |
on: | |
push: | |
branches: [main] | |
merge_group: | |
pull_request: | |
branches: [main] | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
# Automatically cancel in-progress actions on the same branch | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }} | |
cancel-in-progress: true | |
env: | |
REGISTRY: docker.io | |
IMAGE_NAME: trueberryless/trueberryless | |
NODE_VERSION: 18 | |
jobs: | |
docker-push-image: | |
if: contains(github.event.head_commit.message, 'version') || github.event_name == 'workflow_dispatch' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Check if file exists | |
run: | | |
if [ -f .github/artifacts/version.json ]; then | |
echo "File exists" | |
echo "FILE_EXISTS=true" >> $GITHUB_ENV | |
else | |
echo "File does not exist" | |
echo "FILE_EXISTS=false" >> $GITHUB_ENV | |
fi | |
- name: read_json | |
if: ${{ env.FILE_EXISTS == 'true' }} | |
id: version | |
uses: zoexx/github-action-json-file-properties@release | |
with: | |
file_path: ".github/artifacts/version.json" | |
- name: save environment variables | |
if: ${{ env.FILE_EXISTS == 'true' }} | |
run: | | |
echo "MAJOR=${{steps.version.outputs.major}}" >> $GITHUB_ENV | |
echo "MINOR=${{steps.version.outputs.minor}}" >> $GITHUB_ENV | |
echo "PATCH=${{steps.version.outputs.patch}}" >> $GITHUB_ENV | |
- name: create environment variables | |
if: ${{ env.FILE_EXISTS == 'false' }} | |
run: | | |
echo "MAJOR=0" >> $GITHUB_ENV | |
echo "MINOR=0" >> $GITHUB_ENV | |
echo "PATCH=0" >> $GITHUB_ENV | |
- name: echo environment variables | |
run: | | |
echo ${{ env.MINOR }} | |
echo ${{ env.MINOR }} | |
echo ${{ env.MINOR }} | |
- name: Major version | |
if: contains(github.event.head_commit.message, 'major') | |
run: | | |
echo "New major version" | |
echo "MAJOR=$((${{ env.MAJOR }}+1))" >> $GITHUB_ENV | |
echo "MINOR=0" >> $GITHUB_ENV | |
echo "PATCH=0" >> $GITHUB_ENV | |
- name: Minor version | |
if: contains(github.event.head_commit.message, 'minor') | |
run: | | |
echo "New minor version" | |
echo "MINOR=$((${{ env.MINOR }}+1))" >> $GITHUB_ENV | |
echo "PATCH=0" >> $GITHUB_ENV | |
- name: Patch version | |
if: contains(github.event.head_commit.message, 'patch') || github.event_name == 'workflow_dispatch' | |
run: | | |
echo "New patch version" | |
echo "PATCH=$((${{ env.PATCH }}+1))" >> $GITHUB_ENV | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: | | |
${{ env.IMAGE_NAME }}:${{ env.MAJOR}}.${{ env.MINOR}}.${{ env.PATCH}} | |
${{ env.IMAGE_NAME }}:latest | |
labels: ${{ steps.meta.outputs.labels }} | |
- name: Check out the repo | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Create folder if necessary | |
if: ${{ env.FILE_EXISTS == 'false' }} | |
run: mkdir -p .github/artifacts | |
- name: write_json | |
id: create-json | |
uses: jsdaniell/[email protected] | |
with: | |
name: "version.json" | |
json: '{ "major": ${{ env.MAJOR }}, "minor": ${{ env.MINOR }}, "patch": ${{ env.PATCH }} }' | |
dir: '.github/artifacts/' | |
- uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
commit_message: update version.json (automated) |