fix to a specific version #28
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: Build and Dockerize KIET Go Application | |
on: | |
push: | |
branches: | |
- main # Run the workflow on pushes to the main branch | |
pull_request: | |
branches: | |
- main # Run the workflow on pull requests targeting the main branch | |
jobs: | |
build-and-dockerize: | |
runs-on: ubuntu-24.04 | |
steps: | |
# Step 1: Checkout the code | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# Step 2: Set up Go environment | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: 1.23 | |
cache-dependency-path: | | |
eks/go.sum | |
# Step 3: Read and increment version | |
- name: Increment version | |
id: version | |
run: | | |
# Read the current version from the VERSION file | |
VERSION_FILE=eks/VERSION | |
if [ ! -f "$VERSION_FILE" ]; then | |
echo "0.0.0" > $VERSION_FILE | |
fi | |
CURRENT_VERSION=$(cat $VERSION_FILE) | |
# Increment the patch version | |
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION" | |
PATCH=$((PATCH + 1)) | |
NEW_VERSION="$MAJOR.$MINOR.$PATCH" | |
# Write the new version to the file | |
echo "$NEW_VERSION" > $VERSION_FILE | |
echo "version=$NEW_VERSION" >> $GITHUB_ENV | |
# Step 4: Install dependencies | |
- name: Install Go dependencies and build | |
run: | | |
cd eks | |
go mod tidy | |
go build -o keit . | |
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o keit . | |
docker build -t keit:${{ env.version }} . | |
# Step 5: login to ghcr.io | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GTH_TOKEN }} | |
# Step 6: Push Docker image to GitHub Container Registry | |
- name: Push Docker image to GitHub Container Registry | |
run: | | |
docker tag keit:${{ env.version }} ghcr.io/aknostic/keit:${{ env.version }} | |
docker push ghcr.io/aknostic/keit:${{ env.version }} | |
# Step 7: Add and push 'latest' tag | |
- name: Push Docker image with latest tag | |
run: | | |
docker tag keit:${{ env.version }} ghcr.io/aknostic/keit:latest | |
docker push ghcr.io/aknostic/keit:latest | |
# Step 8: Commit updated version file | |
- name: Commit and push updated version | |
run: | | |
git config --local user.name "GitHub Actions" | |
git config --local user.email "[email protected]" | |
git add eks/VERSION | |
git commit -m "Bump version to ${{ env.version }}" | |
git push | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |