Skip to content

Commit

Permalink
Try something
Browse files Browse the repository at this point in the history
  • Loading branch information
Saverio976 committed Sep 1, 2024
1 parent 2a662e9 commit da02fca
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 0 deletions.
95 changes: 95 additions & 0 deletions .github/workflows/dockerc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
on:
push:
branches: [main]

env:
BRANCH: "main"
REGISTRY: "ghcr.io"
REGISTRY_IMAGE: "worldtimezone"

jobs:
release-create:
permissions: write-all
runs-on: ubuntu-latest

outputs:
release: ${{ steps.release.outputs.release_tag }}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- id: release
name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [[ "${{ github.ref }}" == 'refs/heads/main' ]]; then
export GITHUB_OUTPUT=$GITHUB_OUTPUT
bash ./.github/workflows/release.sh "${{ env.BRANCH }}"
else
echo "release_tag=0.0.0" >> $GITHUB_OUTPUT
fi
release-linux-x64:
runs-on: ubuntu-latest
needs: [release-create]

steps:
- name: Checkout
uses: actions/checkout@v4

# docker

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

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

- name: Login to Github 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_IMAGE }}

- name: Build and push Docker image
id: docker_build
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true

# dockerc

- name: Download dockerc
run: curl -Lo dockerc https://github.com/NilsIrl/dockerc/releases/download/v0.3.2/dockerc_x86-64

- name: Give executable permissions to dockerc
run: chmod +x ./dockerc

- name: Create executable amd64
run: ./dockerc --image ghcr.io://worldtimezone:main -o worldtimezone_amd64 --arch amd64
- name: Create executable arm64
run: ./dockerc --image ghcr.io://worldtimezone:main -o worldtimezone_amd64 --arch arm64

# upload

- name: Upload To Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload ${{ needs.release-create.outputs.release }} "./worldtimezone_amd64"
gh release upload ${{ needs.release-create.outputs.release }} "./worldtimezone_arm64"
46 changes: 46 additions & 0 deletions .github/workflows/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
# Release script run in Github CI

BRANCH="$1"

LAST_TAG=$(git tag | sort -t '.' --numeric-sort -k1,1 -k2,2 -k3,3 | tail -n 1)
LAST_TAG_MAJOR=$(echo "$LAST_TAG" | cut -d'.' -f1)
LAST_TAG_MINOR=$(echo "$LAST_TAG" | cut -d'.' -f2)
LAST_TAG_PATCH=$(echo "$LAST_TAG" | cut -d'.' -f3)

git show --compact-summary "$LAST_TAG..HEAD" > CHANGELOG

TAG_MAJOR=""
TAG_MINOR=""
TAG_PATCH=""

WARNINGS=""

if grep -q "^ MAJOR" CHANGELOG; then
TAG_MAJOR=$((LAST_TAG_MAJOR + 1))
TAG_MINOR="0"
TAG_PATCH="0"
elif grep -q "^ MINOR" CHANGELOG; then
TAG_MAJOR=$((LAST_TAG_MAJOR + 0))
TAG_MINOR=$((LAST_TAG_MINOR + 1))
TAG_PATCH="0"
elif grep -q "^ PATCH" CHANGELOG; then
TAG_MAJOR=$((LAST_TAG_MAJOR + 0))
TAG_MINOR=$((LAST_TAG_MINOR + 0))
TAG_PATCH=$((LAST_TAG_PATCH + 1))
else
WARNINGS="$WARNINGS ; This release is created with default bump version because no commits was ok"
TAG_MAJOR=$((LAST_TAG_MAJOR + 0))
TAG_MINOR=$((LAST_TAG_MINOR + 0))
TAG_PATCH=$((LAST_TAG_PATCH + 1))
fi

TAG="$TAG_MAJOR.$TAG_MINOR.$TAG_PATCH"

gh release create "$TAG" \
--title "v$TAG" \
--generate-notes \
--target "$BRANCH"

echo "release_tag=$TAG" >> $GITHUB_OUTPUT
echo "$WARNINGS"
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# WorldTimeZone

Display what time is it for your friend in their timezone.

## Usage

### Binary

Grab a binary for your platform in the latest release

### Docker

1. Build the [Dockerfile](./Dockerfile)
2. Run it with `BOT_TOKEN` env variable set to your discord bot

### If you have any issues, feel free to create an [issue](https://github.com/X-R-G-B/WorldTimeZone/issues)

0 comments on commit da02fca

Please sign in to comment.