Skip to content

Update version from github actions #5

Update version from github actions

Update version from github actions #5

name: fake-smtp-server build
on:
schedule:
- cron: "0 0 * * 0"
push:
branches:
- "**"
tags:
- "v*.*.*"
pull_request:
branches: [ "main" ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Run curl command to get latest version
id: curl_output
run: |
set -x
response=$(curl -s "https://api.github.com/repos/sj26/mailcatcher/releases/latest")
# Parse and extract tag_name from the JSON response
tag_name=$(echo $response | jq -r '.tag_name')
# Remove the leading 'v' from tag_name
echo "latest_version=${tag_name#v}" >> $GITHUB_OUTPUT
- name: Display latest version
run: |
echo "Latest Version: ${{ steps.curl_output.outputs.latest_version }}"
- name: Read version from file
id: read_version
run: |
echo "version=$(cat version.txt)" >> $GITHUB_OUTPUT
- name: Display version from file
run: |
echo "Version from File: ${{ steps.read_version.outputs.version }}"
- name: Check if versions are different
id: check_versions
run: |
if [ "${{ steps.curl_output.outputs.latest_version }}" != "${{ steps.read_version.outputs.version }}" ]; then
echo "Versions are different, running Docker build..."
git checkout -b version-update-${{ github.run_number }}
echo "${{ steps.curl_output.outputs.latest_version }}" > version.txt
echo "build_docker=true" >> $GITHUB_OUTPUT
else
echo "Versions are the same, skipping Docker build."
echo "build_docker=false" >> $GITHUB_OUTPUT
fi
- name: Commit and push changes
if: steps.check_versions.outputs.build_docker == 'true'
run: |
git add version.txt
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions Bot"
git commit -m "Update version to ${{ steps.curl_output.outputs.latest_version }}"
git push origin version-update-${{ github.run_number }}
- name: Create pull request
if: steps.check_versions.outputs.build_docker == 'true'
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr = await github.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Update version to ${{ steps.curl_output.outputs.latest_version }}`,
body: 'Automated pull request to update version.',
head: `version-update-${context.runNumber}`,
base: 'main'
});
- name: Docker meta
if: steps.check_versions.outputs.build_docker == 'true'
id: meta
uses: docker/metadata-action@v4
with:
# list of Docker images to use as base name for tags
images: |
haravich/fake-smtp-server
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Set up QEMU
if: steps.check_versions.outputs.build_docker == 'true'
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
if: steps.check_versions.outputs.build_docker == 'true'
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
if: github.event_name != 'pull_request' && steps.check_versions.outputs.build_docker == 'true'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GHCR
if: github.event_name != 'pull_request' && steps.check_versions.outputs.build_docker == 'true'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
if: github.event_name != 'pull_request' && steps.check_versions.outputs.build_docker == 'true'
uses: docker/build-push-action@v4
with:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: ${{ }}

Check failure on line 136 in .github/workflows/docker-publish.yml

View workflow run for this annotation

GitHub Actions / fake-smtp-server build

Invalid workflow file

The workflow is not valid. .github/workflows/docker-publish.yml (Line: 136, Col: 23): An expression was expected