Update version #4
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: Deploy to Container Registry | |
on: | |
push: | |
branches: | |
- master | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
check-version: | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.check.outputs.version }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Check version | |
id: check | |
shell: bash | |
run: | | |
PPREVIOUS_VERSION=$(git show HEAD~1:Cargo.toml | grep version -m 1 | cut -d '"' -f 2) | |
CURRENT_VERSION=$(grep version Cargo.toml -m 1 | cut -d '"' -f 2) | |
if [ "$PPREVIOUS_VERSION" != "$CURRENT_VERSION" ]; then | |
echo "version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT" | |
fi | |
create-tag: | |
runs-on: ubuntu-latest | |
needs: ["check-version"] | |
if: ${{ needs.check-version.outputs.version != '' }} | |
outputs: | |
tag-exists: ${{ steps.create-tag.outputs.tag_exists }} | |
release-body: ${{ steps.generate-body.outputs.body }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Generate body | |
id: generate-body | |
run: | | |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) | |
git_logs=$(git log "$(git describe --tags --abbrev=0)"..HEAD --oneline) | |
git_logs="${git_logs//$'\n'/$'\n'- }" | |
{ | |
echo "body<<$EOF" | |
echo "- $git_logs" | |
echo "$EOF" | |
} >>"$GITHUB_OUTPUT" | |
shell: bash | |
- uses: rickstaa/action-create-tag@v1 | |
id: create-tag | |
with: | |
tag: ${{ needs.check-version.outputs.version }} | |
tag_exists_error: true | |
message: ${{ needs.check-version.outputs.version }} | |
create-release: | |
runs-on: ubuntu-latest | |
needs: ["check-version", "create-tag"] | |
if: ${{ needs.create-tag.outputs.tag-exists == 'false' }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Create a GitHub release | |
uses: ncipollo/release-action@v1 | |
with: | |
tag: ${{ needs.check-version.outputs.version }} | |
name: ${{ needs.check-version.outputs.version }} | |
body: ${{ needs.create-tag.outputs.release-body }} | |
push-image: | |
runs-on: ubuntu-latest | |
needs: ["check-version", "create-tag", "create-release"] | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
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 }}:${{ needs.check-version.outputs.version }} | |
labels: ${{ steps.meta.outputs.labels }} |