fix: skip latest version output when nil #8
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 | |
on: [push, pull_request] | |
permissions: | |
contents: write | |
packages: write | |
env: | |
GO_VERSION: 1.21 | |
jobs: | |
go-tests: | |
name: Running Go tests | |
runs-on: ubuntu-latest | |
services: | |
mysql: | |
image: mysql:5.7 | |
env: | |
MYSQL_DATABASE: dns | |
MYSQL_ROOT_PASSWORD: 123456 | |
ports: | |
- 3306:3306 | |
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | |
redis: | |
image: redis:6.2.4 | |
ports: | |
- 6379:6379 | |
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
cache-dependency-path: ./go.mod | |
- name: Tests | |
run: | | |
go test -v $(go list ./...) -tags skipCi | |
working-directory: ./ | |
linter: | |
name: Go-Linter | |
runs-on: ubuntu-latest | |
needs: [ go-tests ] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
cache: false | |
# gen a dummy config file | |
- run: touch dummy.yml | |
- name: golangci-lint | |
uses: golangci/golangci-lint-action@v3 | |
with: | |
version: latest | |
args: --disable-all -c dummy.yml -E=gofumpt --max-same-issues=0 --timeout 5m --modules-download-mode=mod | |
backend: | |
name: Backend | |
runs-on: ubuntu-latest | |
needs: [ linter ] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
cache-dependency-path: ./go.mod | |
- run: go version | |
- name: Build | |
run: | | |
go build -trimpath -ldflags "-s -w -X main.version=${{ needs.release.outputs.new_version }}" -o ./bin/semantic-release . | |
go build -trimpath -ldflags "-s -w -X main.version=${{ needs.release.outputs.new_version }}" -tags "analyzer_angular output_teamcity" -o ./bin/semantic-release-full . | |
working-directory: ./ | |
- name: Artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: semantic-release-linux | |
path: ./bin | |
backend-windows: | |
name: Backend-Windows | |
runs-on: windows-2019 | |
needs: [ linter ] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
cache-dependency-path: ./go.mod | |
- run: go version | |
- name: Build | |
run: | | |
go build -trimpath -ldflags "-s -w -X main.version=${{ needs.release.outputs.new_version }}" -o ./bin/semantic-release.exe . | |
go build -trimpath -ldflags "-s -w -X main.version=${{ needs.release.outputs.new_version }}" -tags "analyzer_angular output_teamcity" -o ./bin/semantic-release-full.exe . | |
working-directory: ./ | |
- name: Artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: semantic-release-windows | |
path: ./bin | |
release: | |
name: Release | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' | |
needs: [ backend, backend-windows ] | |
outputs: | |
new_version: ${{ steps.should_push.outputs.new_version }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Fetch Previous version | |
id: get-previous-tag | |
uses: actions-ecosystem/action-get-latest-tag@v1.6.0 | |
- name: mkdir | |
run: | | |
mkdir dist | |
- name: Download Artifact Linux | |
uses: actions/download-artifact@v3 | |
with: | |
name: semantic-release-linux | |
path: ./dist | |
- name: Download Artifact Windows | |
uses: actions/download-artifact@v3 | |
with: | |
name: semantic-release-windows | |
path: ./dist | |
- name: ls | |
run: | | |
ls -l ./dist | |
- name: Release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
run: yarn global add semantic-release @semantic-release/changelog && semantic-release | |
- name: Fetch Current version | |
id: get-current-tag | |
uses: actions-ecosystem/action-get-latest-tag@v1.6.0 | |
- name: Output New Version | |
id: should_push | |
run: | | |
old_version=${{steps.get-previous-tag.outputs.tag}} | |
new_version=${{steps.get-current-tag.outputs.tag }} | |
if [ "$old_version" != "$new_version" ]; then | |
echo "new_version=$new_version" >> $GITHUB_OUTPUT | |
else | |
echo "new_version=" >> $GITHUB_OUTPUT | |
fi | |
docker: | |
runs-on: ubuntu-latest | |
needs: [ release ] | |
if: github.event_name == 'push' && needs.release.outputs.new_version != '' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Go Build Cache for Docker | |
uses: actions/cache@v3 | |
with: | |
path: go-build-cache | |
key: ${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }} | |
- name: inject go-build-cache into docker | |
# v1 was composed of two actions: "inject" and "extract". | |
# v2 is unified to a single action. | |
uses: reproducible-containers/buildkit-cache-dance@v2.1.2 | |
with: | |
cache-source: go-build-cache | |
- name: Login to Docker Hub | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Login to GHCR | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Docker Push | |
uses: docker/build-push-action@v5 | |
if: github.event_name == 'push' | |
with: | |
context: . | |
push: true | |
platforms: linux/amd64 | |
tags: | | |
wulaguy/semantic-release-go:latest | |
wulaguy/semantic-release-go:${{ needs.release.outputs.new_version }} | |
ghcr.io/wintbiit/semantic-release-go:latest | |
ghcr.io/wintbiit/semantic-release-go:${{ needs.release.outputs.new_version }} | |
build-args: | | |
VERSION=${{ needs.release.outputs.new_version }} | |
labels: | | |
org.opencontainers.image.source=https://github.com/wintbiit/semanitc-release-go | |
org.opencontainers.image.revision=${{ github.sha }} | |
org.opencontainers.image.created=${{ github.event.head_commit.timestamp }} | |
org.opencontainers.image.version=${{ needs.release.outputs.new_version }} | |
org.opencontainers.image.title=semanitc-release-go ${{ needs.release.outputs.new_version }} | |
org.opencontainers.image.description="flexible dns with source cidr dispatch and database record storage support" | |
org.opencontainers.image.licenses=AGPL-3.0 | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |