Skip to content

Commit

Permalink
docs: add golangci-lint.yml & fix workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
wayjam committed Oct 26, 2024
1 parent e41d000 commit f9f7c50
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 166 deletions.
40 changes: 0 additions & 40 deletions .github/chglog/CHANGELOG.tpl.md

This file was deleted.

27 changes: 0 additions & 27 deletions .github/chglog/config.yml

This file was deleted.

18 changes: 9 additions & 9 deletions .github/workflows/build-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write

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

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version: '~1.22'

- name: Build binaries
run: |
BUILD_TIME=`date +%FT%T%z`
GIT_REV=`git rev-parse --short HEAD`
BUILD_TIME=$(date +%FT%T%z)
GIT_REV=$(git rev-parse --short HEAD)
GO_VERSION=$(go version)
LDFLAGS=-ldflags "-w -s \
-X 'github.com/wayjam/tv-mixproxy/internal.Version=${{ inputs.version }}' \
LDFLAGS="-X 'github.com/wayjam/tv-mixproxy/internal.Version=${{ inputs.version }}' \
-X 'github.com/wayjam/tv-mixproxy/internal.GitRev=${GIT_REV}' \
-X 'github.com/wayjam/tv-mixproxy/internal.BuildTime=${BUILD_TIME}' \
-X 'github.com/wayjam/tv-mixproxy/internal.GoVersion=${GO_VERSION}' \
"
GOOS=linux GOARCH=amd64 go build "${LDFLAGS}" -o build/tv-mixproxy-linux-amd64 ./cmd/tv-mixproxy
GOOS=linux GOARCH=arm64 go build "${LDFLAGS}" -o build/tv-mixproxy-linux-arm64 ./cmd/tv-mixproxy
-w -s"
GOOS=linux GOARCH=amd64 go build -ldflags "${LDFLAGS}" -o build/tv-mixproxy-linux-amd64 ./cmd/tv-mixproxy
GOOS=linux GOARCH=arm64 go build -ldflags "${LDFLAGS}" -o build/tv-mixproxy-linux-arm64 ./cmd/tv-mixproxy
- name: Get Release
id: get_release
Expand Down
53 changes: 28 additions & 25 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ on:
workflow_dispatch:
inputs:
version:
description: 'Version tag for the Docker image'
description: "Version tag for the Docker image"
required: true
type: string
dry_run:
description: 'Dry run (true/false)'
description: "Dry run (true/false)"
required: true
type: boolean
default: false
Expand All @@ -27,7 +27,6 @@ env:
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}


jobs:
build-and-push:
runs-on: ubuntu-latest
Expand All @@ -52,40 +51,44 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Prepare Version
id: prepare_version
run: |
enable_ref="false"
enable_raw="false"
if [ -z "${{ inputs.version }}" ]; then
enable_ref="true"
else
enable_raw="true"
fi
echo "enable_ref=${enable_ref}" >> $GITHUB_OUTPUT
echo "enable_raw=${enable_raw}" >> $GITHUB_OUTPUT
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=auto
tags: |
type=ref,enable=${{ steps.prepare_version.outputs.enable_ref }},event=tag
type=raw,enable=${{ steps.prepare_version.outputs.enable_raw }},value=${{ inputs.version }}
- name: Get Version
id: version
run: |
if [ -z "${{ inputs.version }}" ]; then
echo "tag=${{ steps.meta.outputs.tags }}" >> $GITHUB_OUTPUT
else
echo "tag=${{ inputs.version }}" >> $GITHUB_OUTPUT
fi
echo "The tag is ${{ steps.version.outputs.tag }}"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

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

- name: Build and push Docker image
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
context: .
push: true
tags: ${{ steps.version.outputs.tag }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: VERSION=${{ steps.version.outputs.tag }}

- name: Install cosign
uses: sigstore/cosign-installer@v3
with:
cosign-release: 'v2.2.4'

- name: Sign the published Docker image
env:
TAGS: ${{ steps.version.outputs.tag }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
9 changes: 8 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ run-name: Build and Publish (${{ github.ref }}) ${{ inputs.dry_run && '(🧪 Dry
on:
push:
tags:
- 'v*'
- v*
release:
types: [published, released]

workflow_dispatch:
inputs:
Expand All @@ -17,6 +19,11 @@ on:
type: string
default: "binary,docker"

permissions:
contents: write
packages: write
id-token: write

jobs:
# Get the current tag
get_tag:
Expand Down
90 changes: 42 additions & 48 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 0x📦 Release New Version
run-name: 📦 Release ${{ inputs.semver }} by @${{ github.actor }} ${{ inputs.dry_run && '(🧪 Dry-Run)' || '' }}
run-name: 📦 Release ${{ inputs.semver }}/${{ inputs.custom_version }} by @${{ github.actor }} ${{ inputs.dry_run && '(🧪 Dry-Run)' || '' }}

on:
workflow_dispatch:
Expand All @@ -13,7 +13,7 @@ on:
- major
required: true
custom_version:
description: Manual Custom Version (Special Purpose, v*)
description: Manual Custom Version (Special Purpose, e.g. 1.0.0)
type: string
required: false
dry_run:
Expand All @@ -22,67 +22,61 @@ on:
default: false

jobs:
check_tests:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
should_test: ${{ steps.check.outputs.should_test }}
steps:
- name: Check if tests have already run
id: check
run: |
CHECK_RUNS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/commits/${{ github.sha }}/check-runs")
ALL_PASSED=$(echo "$CHECK_RUNS" | jq -r '.check_runs | all(.conclusion == "success")')
echo "ALL_PASSED=$ALL_PASSED"
if [ "$ALL_PASSED" == "true" ]; then
echo "All tests have already passed for this commit. Skipping tests."
echo "should_test=false" >> $GITHUB_OUTPUT
else
echo "Some tests haven't run or passed for this commit. Running tests."
echo "should_test=true" >> $GITHUB_OUTPUT
fi
test:
needs: check_tests
if: needs.check_tests.outputs.should_test == 'true'
uses: ./.github/workflows/test.yml

release:
needs: test
needs: [check_tests, test]
if: always() && (needs.check_tests.outputs.should_test == 'false' || needs.test.result == 'success')
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
steps:
- name: Checkout Code
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: master
fetch-depth: 0

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20.x
registry-url: https://registry.npmjs.org/

- name: Setup semver
run: npm install -g semver

- name: Handle Version Number
run: |
PREV_VERSION="$(git describe --tags --abbrev=0 --match 'v*')"
if [ -n "${{ inputs.custom_version }}" ]; then
NEXT_VERSION="${{ inputs.custom_version }}"
else
NEXT_VERSION="v$(semver --increment ${{ inputs.semver }} ${PREV_VERSION})"
fi
echo "PREV_VERSION=${PREV_VERSION}" >> $GITHUB_ENV
echo "VERSION=${NEXT_VERSION}" >> $GITHUB_ENV
- name: Print Next Version
run: echo "${VERSION}"

- name: Setup git-chglog
run: |
curl -sL $(curl -s https://api.github.com/repos/git-chglog/git-chglog/releases/latest \
| grep -oP '"https://.+linux_amd64.tar.gz"' | tr -d \") | tar -C /usr/local/bin -xz git-chglog
git-chglog --version
- name: Version Changelog
id: changelog
run: |
# prepend changelog
changelog=$(git-chglog --config .github/chglog/config.yml --next-tag "${VERSION}" "${VERSION}")
echo "changelog=${changelog}\n" >> "$GITHUB_OUTPUT"

- name: Bump version and push tag
id: tag_version
uses: mathieudutour/github-tag-action@v6.2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: ${{ env.VERSION }}
default_bump: ${{ inputs.semver }}
custom_tag: ${{ inputs.custom_version }}

- name: Create a GitHub release
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.tag_version.outputs.VERSION }}
tag: ${{ steps.tag_version.outputs.new_tag }}
name: Release ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.changelog.outputs.changelog }}
body: ${{ steps.tag_version.outputs.changelog }}
draft: ${{ inputs.dry_run }}

- name: Dispatch Build
uses: benc-uk/workflow-dispatch@v1
with:
workflow: build.yml
inputs: '{ "dry_run": ${{ inputs.dry_run }} }'
Loading

0 comments on commit f9f7c50

Please sign in to comment.