Make release #18
Workflow file for this run
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: Make release | |
on: | |
push: | |
tags: | |
- '*' | |
jobs: | |
Build-and-release: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Check Changelog | |
run: | | |
TAG=$(git tag --points-at $GITHUB_SHA | sed 's/^v//') | |
CHANGELOG_ENTRY="## [$TAG] -" | |
if ! grep -Fq "$CHANGELOG_ENTRY" CHANGELOG.md; then | |
echo "Error: Changelog entry not found for tag $TAG in CHANGELOG.md" | |
exit 1 | |
fi | |
# A fallback | |
cat CHANGELOG.md > release_body | |
# Fetch lines from CHANGELOG between the previous and current tag | |
PREVIOUS_TAG=$(git tag -l | sort -V | tail -n 2 | head -n 1 | sed 's/^v//') | |
if [ -n "$PREVIOUS_TAG" ]; then | |
PREVIOUS_TAG_ENTRY="## [$PREVIOUS_TAG] -" | |
PREVIOUS_TAG_LINE=$(grep -nF "$PREVIOUS_TAG_ENTRY" CHANGELOG.md | cut -d: -f1) | |
if [ -n "$PREVIOUS_TAG_LINE" ]; then | |
PREVIOUS_TAG_LINE=$((PREVIOUS_TAG_LINE - 1)) | |
CURRENT_TAG_LINE=$(grep -nF "$CHANGELOG_ENTRY" CHANGELOG.md | tail -n 1 | cut -d: -f1) | |
sed -n "${CURRENT_TAG_LINE},${PREVIOUS_TAG_LINE}p" CHANGELOG.md > release_body | |
fi | |
fi | |
- name: Set up Go | |
uses: actions/setup-go@v2 | |
with: | |
go-version: 1.21 | |
- name: Run tests | |
run: | | |
go test mcv_test.go | |
- name: Variables | |
id: vars | |
run: | | |
echo "BUILDS_DIR=builds" >> $GITHUB_OUTPUT | |
echo "LINUX_BUILD_FILE=mcv_linux64_${{ github.ref_name }}.zip" >> $GITHUB_OUTPUT | |
echo "OSX_BUILD_FILE=mcv_osx_${{ github.ref_name }}.zip" >> $GITHUB_OUTPUT | |
echo "WIN_BUILD_FILE=mcv_windows_${{ github.ref_name }}.zip" >> $GITHUB_OUTPUT | |
- name: Build Linux | |
run: | | |
mkdir -p ${{ steps.vars.outputs.BUILDS_DIR }}/ | |
env GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" ./mcv.go | |
zip -m -j ${{ steps.vars.outputs.BUILDS_DIR }}/${{ steps.vars.outputs.LINUX_BUILD_FILE }} ./mcv | |
- name: Build OSX | |
run: | | |
env GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w" ./mcv.go | |
zip -m -j ${{ steps.vars.outputs.BUILDS_DIR }}/${{ steps.vars.outputs.OSX_BUILD_FILE }} ./mcv | |
- name: Build Windows | |
run: | | |
env GOOS=windows GOARCH=amd64 go build -ldflags "-s -w" ./mcv.go | |
zip -m -j ${{ steps.vars.outputs.BUILDS_DIR }}/${{ steps.vars.outputs.WIN_BUILD_FILE }} ./mcv.exe | |
- name: Release | |
uses: actions/create-release@v1 | |
id: create_release | |
with: | |
draft: false | |
prerelease: false | |
release_name: ${{ github.ref_name }} | |
tag_name: ${{ github.ref_name }} | |
body_path: release_body | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
- name: Upload Linux artifact | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ${{ steps.vars.outputs.BUILDS_DIR }}/${{ steps.vars.outputs.LINUX_BUILD_FILE }} | |
asset_name: ${{ steps.vars.outputs.LINUX_BUILD_FILE }} | |
asset_content_type: application/gzip | |
- name: Upload OSX artifact | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ${{ steps.vars.outputs.BUILDS_DIR }}/${{ steps.vars.outputs.OSX_BUILD_FILE }} | |
asset_name: ${{ steps.vars.outputs.OSX_BUILD_FILE }} | |
asset_content_type: application/gzip | |
- name: Upload Windows artifact | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ${{ steps.vars.outputs.BUILDS_DIR }}/${{ steps.vars.outputs.WIN_BUILD_FILE }} | |
asset_name: ${{ steps.vars.outputs.WIN_BUILD_FILE }} | |
asset_content_type: application/gzip |