Skip to content

Commit

Permalink
Update docker-image.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
ellitedev committed Dec 3, 2023
1 parent 8bd7246 commit c8c582f
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
name: Push to registry

on:
create:
push:
tags:
- 'v*'

jobs:
docker:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Install jq if not present
run: |
if ! command -v jq &> /dev/null
then
sudo apt-get update
sudo apt-get install -y jq
fi
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
Expand All @@ -25,35 +19,42 @@ jobs:
registry: http://registry.ellite.dev/
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/}
- name: Build and push
uses: docker/build-push-action@v5
with:
push: true
tags: registry.ellite.dev/raibu-web:${{ github.ref_name }}
- name: Update latest tag
run: |
LATEST_TAG=$(curl -s https://api.github.com/repos/${{ github.repository }}/tags | jq -r '.[] | select(type=="object") | .name' | sort -V | tail -n 1)
CURRENT_TAG=${{ github.ref_name }}
SEMVER_REGEX="^v([0-9]+)\.([0-9]+)\.([0-9]+)$"
if [[ ! $CURRENT_TAG =~ $SEMVER_REGEX ]]; then
echo "Error: Tag $CURRENT_TAG does not follow semantic versioning"
exit 1
fi
if [[ "$(printf '%s\n' "$LATEST_TAG" "$CURRENT_TAG" | sort -V | tail -n 1)" == "$CURRENT_TAG" ]]; then
docker tag registry.ellite.dev/raibu-web:${{ github.ref_name }} registry.ellite.dev/raibu-web:latest
docker push registry.ellite.dev/raibu-web:latest
fi
tags: registry.ellite.dev/raibu-web:${{ steps.get_version.outputs.VERSION }}
- name: Check if tag is the latest
id: check_latest
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const tags = await github.repos.listTags({
owner: context.repo.owner,
repo: context.repo.repo,
});
const versions = tags.data.map(tag => tag.name).sort((a, b) => semver.rcompare(a, b));
return versions[0] === '${{ steps.get_version.outputs.VERSION }}';
- name: Build and push latest
if: steps.check_latest.outputs.result == 'true'
uses: docker/build-push-action@v5
with:
push: true
tags: registry.ellite.dev/raibu-web:latest
- name: Test image
run: |
docker pull registry.ellite.dev/raibu-web:${{ github.ref_name }}
docker pull registry.ellite.dev/raibu-web:${{ steps.get_version.outputs.VERSION }}
if [ $? -eq 0 ]; then
echo "Image exists"
else
echo "Image does not exist"
exit 1
fi
tarball:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -69,4 +70,4 @@ jobs:
uses: actions/upload-artifact@v2
with:
name: raibu-web
path: raibu-web.tar.gz
path: raibu-web.tar.gz

0 comments on commit c8c582f

Please sign in to comment.