Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
actions: try new release method without name of project
Browse files Browse the repository at this point in the history
  • Loading branch information
Divkix committed Sep 6, 2022
1 parent caace77 commit b331ef2
Showing 1 changed file with 43 additions and 41 deletions.
84 changes: 43 additions & 41 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ on:
description: 'Tag to release'
required: true

env:
ProjectName: watermarkbot

jobs:
# only run this step when the tag is not already created
create-tag:
name: Create new tag
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -25,84 +23,88 @@ jobs:
git config --global user.email "[email protected]"
git config --global user.name "Divanshu Chauhan"
tag=${{ github.event.inputs.tag }} # if triggered by workflow_dispatch
if [ -z "$tag" ]; then
tag=${GITHUB_REF#refs/tags/}
fi
git tag -f -a -m "$tag" "$tag"
git push -f origin "$tag"
# fetch some info from repo such as latest tag and name in lowercase
get-repo-info:
name: Get Repo Info
runs-on: ubuntu-latest
needs: create-tag
steps:
- name: Checkout current repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get Latest Tag
id: get_tag
run: |-
tag="$(git tag | sort -V | tail -1)"
echo "::set-output name=tag::$(git tag | sort -V | tail -1)"
- name: Lowercase required vars
id: lowercase
run: |-
echo "::set-output name=project_name::$(echo ${{ github.event.repository.name }} | tr '[:upper:]' '[:lower:]')"
echo "::set-output name=repo_name::$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')"
outputs:
tag: ${{ steps.get_tag.outputs.tag }}
project_name: ${{ steps.lowercase.outputs.project_name }}
repo_name: ${{ steps.lowercase.outputs.repo_name }}

# build the docker image and push it to docker hub and ghcr
docker-build:
name: Build Image
needs: create-tag
name: Build and Push Docker Images
needs: get-repo-info
runs-on: ubuntu-latest

steps:
- name: Checkout current repo
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set ENV Variables
id: vars
run: |
IMG="$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')"
TAG="$(git tag | sort -V | tail -1)"
echo "BUILD_VER=${TAG}" >> $GITHUB_ENV
echo "::set-output name=tag::${TAG}"
echo "IMAGE=${IMG}" >> $GITHUB_ENV
echo "BUILD_DATE=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV
echo "GIT_SHA=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_ENV
echo "GIT_REF=$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match)" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build and push
id: docker_build
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
ghcr.io/${{ env.IMAGE }}:latest
ghcr.io/${{ env.IMAGE }}:${{ env.BUILD_VER }}
${{ env.IMAGE }}:latest
${{ env.IMAGE }}:${{ env.BUILD_VER }}
labels: |
tags: |-
ghcr.io/${{ needs.get-repo-info.outputs.repo_name }}:latest
ghcr.io/${{ needs.get-repo-info.outputs.repo_name }}:${{ needs.get-repo-info.outputs.tag }}
${{ needs.get-repo-info.outputs.repo_name }}:latest
${{ needs.get-repo-info.outputs.repo_name }}:${{ needs.get-repo-info.outputs.tag }}
labels: |-
org.opencontainers.image.authors=${{ github.repository_owner }}
org.opencontainers.image.created=${{ env.BUILD_DATE }}
org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }}
org.opencontainers.image.ref.name=${{ env.GIT_REF }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.version=${{ env.BUILD_VER }}
outputs:
BUILD_VER: ${{ steps.vars.outputs.tag }}
org.opencontainers.image.source=https://github.com/${{ needs.get-repo-info.outputs.repo_name }}
org.opencontainers.image.version=${{ needs.get-repo-info.outputs.tag }}
# update description of the docker image on docker hub
update-dockerhub-description:
name: Update Description
name: Update DockerHub Description
needs: docker-build
runs-on: ubuntu-latest
steps:
Expand All @@ -119,18 +121,18 @@ jobs:
runs-on: ubuntu-latest
needs:
- docker-build
- create-tag
- get-repo-info
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Release
uses: softprops/action-gh-release@v1
with:
name: ${{ needs.docker-build.outputs.BUILD_VER }}
tag_name: ${{ needs.docker-build.outputs.BUILD_VER }}
name: ${{ needs.get-repo-info.outputs.tag }}
tag_name: ${{ needs.get-repo-info.outputs.tag }}
body: |-
${{ github.event.repository.name }} ${{ needs.docker-build.outputs.BUILD_VER }}
${{ github.event.repository.name }} ${{ needs.get-repo-info.outputs.tag }}
Docker Images:
`ghcr.io/${{ github.repository_owner }}/${{ env.ProjectName }}:${{ needs.docker-build.outputs.BUILD_VER }}`
`docker.io/${{ github.repository_owner }}/${{ env.ProjectName }}:${{ needs.docker-build.outputs.BUILD_VER }}`
`ghcr.io/${{ github.repository_owner }}/${{ needs.get-repo-info.outputs.repo_name }}:${{ needs.get-repo-info.outputs.tag }}`
`docker.io/${{ github.repository_owner }}/${{ needs.get-repo-info.outputs.repo_name }}:${{ needs.get-repo-info.outputs.tag }}`

0 comments on commit b331ef2

Please sign in to comment.