Skip to content

workflows

workflows #5

Workflow file for this run

name: CD
on:
push:
tags:
- "v*"
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.23"
- name: Install dependencies
run: go mod download
- name: Run tests
run: go test -v ./...
- name: Build
run: |
GOOS=linux GOARCH=amd64 go build -o sqlmapper-linux-amd64
GOOS=darwin GOARCH=amd64 go build -o sqlmapper-darwin-amd64
GOOS=windows GOARCH=amd64 go build -o sqlmapper-windows-amd64.exe
- name: Generate changelog
id: changelog
uses: actions/github-script@v6
with:
script: |
const { data: releases } = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
})
const previous = releases[0]?.tag_name
const current = context.ref.replace('refs/tags/', '')
const { data: commits } = await github.rest.repos.compareCommits({
owner: context.repo.owner,
repo: context.repo.repo,
base: previous || '',
head: current,
})
const changelog = commits.commits
.map(commit => `- ${commit.commit.message}`)
.join('\n')
return changelog
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: |
Changes in this Release:
${{ steps.changelog.outputs.result }}
draft: false
prerelease: false
- name: Upload Linux Binary
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./sqlmapper-linux-amd64
asset_name: sqlmapper-linux-amd64
asset_content_type: application/octet-stream
- name: Upload macOS Binary
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./sqlmapper-darwin-amd64
asset_name: sqlmapper-darwin-amd64
asset_content_type: application/octet-stream
- name: Upload Windows Binary
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./sqlmapper-windows-amd64.exe
asset_name: sqlmapper-windows-amd64.exe
asset_content_type: application/octet-stream
docker:
name: Push Docker image
runs-on: ubuntu-latest
needs: release
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: |
mstgnz/sqlmapper:latest
mstgnz/sqlmapper:${{ github.ref_name }}