Skip to content

fix: change actions context - maybe this is correct? #58

fix: change actions context - maybe this is correct?

fix: change actions context - maybe this is correct? #58

Workflow file for this run

name: "Build and push"
on:
push:
branches: [ main ]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
with:
go-version: 1.23
cache: false
- uses: actions/checkout@v4
- name: go-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout 5m0s
# Detect services that need to be built via the builder
detect-services:
runs-on: ubuntu-latest
outputs:
services: ${{ steps.detect-services.outputs.services }}
steps:
- uses: actions/setup-go@v4
with:
go-version: 1.23
cache: false
- uses: actions/checkout@v4
with:
fetch-depth: '0'
# Setup Go so we can run the builder
- name: detect-services
id: detect-services
run: |
services=$(go run builder/main.go)
echo "Raw services output: $services"
echo "services=$services" >> $GITHUB_OUTPUT
- name: print-services
run: |
echo "Services: ${{ steps.detect-services.outputs.services }}"
build-and-publish:
needs: [detect-services, lint]
if: needs.detect-services.outputs.services != '[]' # Only run if there are services to build
runs-on: ubuntu-latest
strategy:
matrix:
service: ${{ fromJson(needs.detect-services.outputs.services) }}
steps:
- uses: actions/checkout@v4
- name: "Identify Environment"
shell: bash
run: |
tag_prefix="ghcr.io/emortalmc/${{ matrix.service }}"
tags=""
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
tags="$tag_prefix:${{ github.sha }},$tag_prefix:latest"
else
tags="$tag_prefix:${{ github.sha }}"
fi
echo "DOCKER_TAGS=$tags" >> "$GITHUB_ENV"
- name: "Login to container registry"
uses: "docker/login-action@v2"
with:
registry: "ghcr.io"
username: "${{ github.actor }}"
password: "${{ secrets.GITHUB_TOKEN }}"
- name: "Set up Docker Buildx"
uses: "docker/setup-buildx-action@v2"
- name: "Build and push"
uses: "docker/build-push-action@v4"
with:
context: "./services/${{ matrix.service }}"
file: "./services/${{ matrix.service }}/Dockerfile"
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ env.DOCKER_TAGS }}
deploy:
needs: [build-and-publish, detect-services]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' # Only run on main branch
env:
SERVICES: ${{ needs.detect-services.outputs.services }}
steps:
- name: "Checkout"
uses: "actions/checkout@v4"
with:
repository: "emortalmc/argocd-deployments"
ref: "main"
token: "${{ secrets.DEPLOYMENTS_REPO_TOKEN }}"
- name: "Update image version"
shell: "bash"
# git commit -a automatically adds files that have been modified
run: |
echo "Services: $SERVICES"
services_array=($(echo $SERVICES | jq -r '.[]'))
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
for service in "${services_array[@]}"; do
echo "Updating image for $service to ${{ github.sha }}"
sed -i "s|version: .*|version: ${{ github.sha }}|g" "service/values/$service.yaml"
git commit -a -m "Update $service to ${{ github.sha }}"
done
git push https://😛:[email protected]/emortalmc/argocd-deployments.git
env:
PUSH_TOKEN: "${{ secrets.DEPLOYMENTS_REPO_TOKEN }}"