diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index df743f0..34f9208 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -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 @@ -26,8 +32,11 @@ 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 @@ -35,4 +44,7 @@ jobs: 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 }} + diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 7319dd3..f7d9d71 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -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 @@ -17,14 +20,17 @@ 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 @@ -32,3 +38,12 @@ jobs: 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 }} + diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..f012f28 --- /dev/null +++ b/.github/workflows/test.yaml @@ -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