Merge pull request #49 from wiemanboy/feature/overwrite-release #7
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: Create Docker image | |
on: | |
push: | |
branches: | |
- master | |
- release/* | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install jq | |
run: sudo apt-get install jq | |
- name: Get version from package.json | |
id: get_version | |
run: | | |
VERSION=$(jq -r '.version' package.json) | |
echo "Version: $VERSION" | |
echo "VERSION=${VERSION}" >> $GITHUB_ENV | |
- name: Authorize in Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Build and push | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: | | |
${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_IMAGE_NAME }}:${{ env.VERSION }} | |
${{ github.ref == 'refs/heads/master' && format('{0}/{1}:latest', secrets.DOCKER_HUB_USERNAME, vars.DOCKER_IMAGE_NAME) || '' }} | |
- name: Draft release | |
uses: release-drafter/release-drafter@v6 | |
env: | |
GITHUB_TOKEN: ${{ secrets.TOKEN }} | |
with: | |
name: ${{ github.event.repository.name }} v${{ env.VERSION }} | |
tag: ${{ env.VERSION }} | |
header: | | |
[> DockerHub](https://hub.docker.com/r/${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_IMAGE_NAME }}/tags?name=${{ env.VERSION }}) | |
```bash | |
docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_IMAGE_NAME }}:${{ env.VERSION }} | |
``` | |
- name: Publish Draft | |
env: | |
GITHUB_TOKEN: ${{ secrets.TOKEN }} | |
run: | | |
existing_release=$(gh release view "${{ env.VERSION }}" --json id --jq '.id // empty') | |
if [[ -n "$existing_release" ]]; then | |
echo "Deleting existing release for version ${{ env.VERSION }}" | |
gh release delete "${{ env.VERSION }}" --yes --repo ${{ github.repository }} | |
fi | |
echo "Publishing new release for version ${{ env.VERSION }}" | |
gh release edit "${{ env.VERSION }}" --draft=false --repo ${{ github.repository }} |