Skip to content

Commit

Permalink
ci: Fix docker releases
Browse files Browse the repository at this point in the history
Automate docker releases workflow,
Call workflow from release when there is a new version
Pass version as input to docker workflow
  • Loading branch information
coolapso committed Nov 17, 2024
1 parent e3eb3f7 commit 3cbd4d5
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 11 deletions.
24 changes: 18 additions & 6 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
name: Docker
name: docker
on:
workflow_dispatch:
inputs:
release_tag:
required: true
description: The release tag to build
workflow_call:
release:
types: [published, released, created]
inputs:
release_tag:
type: string
required: true

jobs:
release:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -26,13 +32,19 @@ jobs:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: set tag
run: echo "DOCKER_TAG=$(git describe --tags --abbrev=0 | sed -E 's/^v//g')" >> $GITHUB_ENV
- name: Set docker_tag
run: |
echo "got input: '${{ inputs.release_tag }}'"
echo "DOCKER_TAG=$(echo '${{ inputs.release_tag }}' | sed -E 's/^v//g')" >> $GITHUB_ENV
echo "Going to build: $DOCKER_TAG || '${{ env.DOCKER_TAG }}'"
- name: Build and push
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: coolapso/youtube-exporter:latest,coolapso/youtube-exporter:${{ env.DOCKER_TAG }}
build-args:
VERSION=${{ inputs.release_tag }}


25 changes: 20 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
name: release
on:
name: Release
on:
workflow_dispatch:
push:
branches:
- 'dev'
- 'main'

jobs:
tests:
uses: coolapso/prometheus-youtube-exporter/.github/workflows/test.yaml@main

release:
needs: tests
runs-on: ubuntu-latest
permissions:
contents: write
Expand All @@ -17,18 +20,30 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.23
go-version: '>=1.23'
- uses: go-semantic-release/action@v1
id: semrel
with:
hooks: goreleaser
custom-arguments: '--commit-analyzer-opt patch_release_rules=fix,ref,build'
hooks: goreleaser
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AUR_KEY: ${{ secrets.AUR_KEY }}
DISCORD_WEBHOOK_ID: ${{ secrets.DISCORD_WEBHOOK_ID }}
DISCORD_WEBHOOK_TOKEN: ${{ secrets.DISCORD_WEBHOOK_TOKEN }}

- name: Update Docker Hub Description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: coolapso/youtube-exporter

docker:
needs: release
uses: coolapso/prometheus-youtube-exporter/.github/workflows/docker.yaml@main
if: ${{ needs.release.outputs.version != '' }}
secrets: inherit
with:
release_tag: ${{ needs.release.outputs.version }}

46 changes: 46 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: test

on:
workflow_call:
workflow_dispatch:
pull_request:
push:
branches:
- '**'
- '!main'


jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '>=1.23'

- name: Install dependencies
run: go get .

- name: Check formating
run: |
changedFiles=$(go fmt ./...)
if [[ -n $changedFiles ]]; then
echo -e "Follwing files are not formated:\n${changedFiles}"
exit 1
fi
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
only-new-issues: true

- name: Run tests
run: go test -cover ./...

- name: test build
run: go build -o live-server

0 comments on commit 3cbd4d5

Please sign in to comment.