Skip to content

Commit

Permalink
Merge pull request #72 from partyoffice/improve-ci
Browse files Browse the repository at this point in the history
Feature: Improve ci
  • Loading branch information
Nikos410 authored Nov 11, 2021
2 parents 096aa05 + 83a8592 commit 0e7491b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 45 deletions.
79 changes: 43 additions & 36 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,55 @@
name: Release

on:
workflow_dispatch:
inputs:
version:
description: 'The version number of the release'
required: true
push:
branches:
- master

jobs:
release:
runs-on: ubuntu-latest

steps:
- name: Merge develop into master
uses: everlytic/[email protected]
with:
github_token: ${{ github.token }}
source_ref: 'develop'
target_branch: 'master'
commit_message_template: 'Release v${{ github.event.inputs.version }}'

- name: Checkout master
- name: Checkout # Don't use actions/checkout@v2 because we need the tags
run: |
git clone https://github.com/partyoffice/spotifete.git ./
git checkout -f master
- name: Create release tag
run: |
git tag v${{ github.event.inputs.version }}
git push https://Nikos410:${{ secrets.GITHUB_TOKEN }}@github.com/partyoffice/spotifete.git v${{ github.event.inputs.version }}
- name: Merge master back into develop
- name: Get merged pull request
id: merged-pr
uses: remihq/action-get-merged-pull-request@v1
with:
github_token: ${{ github.token }}

- name: Set release version
id: release-version
env:
PR_TITLE: ${{ steps.merged-pr.outputs.title }}
PR_LABELS: ${{ steps.merged-pr.outputs.labels }}
run: |
git checkout -f develop
git merge --ff-only master
git push https://Nikos410:${{ secrets.GITHUB_TOKEN }}@github.com/partyoffice/spotifete.git develop
VERSION_TAG=$(git describe --tags)
VERSION_MAJOR=$(echo $VERSION_TAG | sed -r 's/[^0-9]*([0-9]+)[.]([0-9]+)[.]([0-9])+.*/\1/')
VERSION_MINOR=$(echo $VERSION_TAG | sed -r 's/[^0-9]*([0-9]+)[.]([0-9]+)[.]([0-9])+.*/\2/')
VERSION_PATCH=$(echo $VERSION_TAG | sed -r 's/[^0-9]*([0-9]+)[.]([0-9]+)[.]([0-9])+.*/\3/')
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
if [[ $PR_TITLE = Feature:* ]] || [[ $PR_LABELS = *Feature* ]]
then
RELEASE_VERSION_MAJOR=$VERSION_MAJOR
RELEASE_VERSION_MINOR=$((VERSION_MINOR+1))
RELEASE_VERSION_PATCH=0
else
RELEASE_VERSION_MAJOR=$VERSION_MAJOR
RELEASE_VERSION_MINOR=$VERSION_MINOR
RELEASE_VERSION_PATCH=$((VERSION_PATCH+1))
fi
- name: Build executable
run: CGO_ENABLED=0 go build -v -o ./ ./...
RELEASE_VERSION=$RELEASE_VERSION_MAJOR.$RELEASE_VERSION_MINOR.$RELEASE_VERSION_PATCH
echo "::set-output name=release_version::$RELEASE_VERSION"
- name: Create release tag
run: |
git tag v${{ steps.release-version.outputs.release_version }}
git push https://Nikos410:${{ secrets.GITHUB_TOKEN }}@github.com/partyoffice/spotifete.git v${{ steps.release-version.outputs.release_version }}
- name: Login to Docker Hub
uses: docker/login-action@v1
Expand All @@ -61,22 +68,22 @@ jobs:
context: ./
file: ./Dockerfile
push: true
tags: nikos410/spotifete:${{ github.event.inputs.version }}
tags: nikos410/spotifete:${{ steps.release-version.outputs.release_version }},nikos410/spotifete:latest

- name: Publish release
id: publish-release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ github.event.inputs.version }}
release_name: Release v${{ github.event.inputs.version }}
body: 'Release v${{ github.event.inputs.version }}'
tag_name: v${{ steps.release-version.outputs.release_version }}
release_name: Release v${{ steps.release-version.outputs.release_version }}
body: ${{ steps.merged-pr.outputs.title }}
draft: false
prerelease: false

- name: Package files for release
run: tar -cvzf spotifete-v${{ github.event.inputs.version }}.tar.gz ./spotifete ./resources ./LICENSE
run: tar -cvzf spotifete-v${{ steps.release-version.outputs.release_version }}.tar.gz ./spotifete ./resources ./LICENSE

- name: Upload Release Asset
id: upload-release-asset
Expand All @@ -85,6 +92,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.publish-release.outputs.upload_url }}
asset_path: spotifete-v${{ github.event.inputs.version }}.tar.gz
asset_name: spotifete-v${{ github.event.inputs.version }}.tar.gz
asset_path: spotifete-v${{ steps.release-version.outputs.release_version }}.tar.gz
asset_name: spotifete-v${{ steps.release-version.outputs.release_version }}.tar.gz
asset_content_type: application/gzip
7 changes: 3 additions & 4 deletions .github/workflows/build.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
name: Build
name: Test

on:
push:
pull_request:

jobs:
build:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
- name: Checkout
uses: actions/checkout@v2

- name: Set up Go
Expand Down
15 changes: 10 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
FROM alpine:3.14
FROM golang:1.17-alpine AS builder

WORKDIR /opt/spotifete
WORKDIR /go/src/github.com/partyoffice/spotifete
COPY . .

ENV CGO_ENABLED=0
RUN go build -v -trimpath -o ./ ./...

COPY ./spotifete /opt/spotifete/spotifete
COPY ./resources /opt/spotifete/resources
FROM alpine:latest

WORKDIR /opt/spotifete

COPY --from=builder /go/src/github.com/partyoffice/spotifete ./
RUN chmod +x /opt/spotifete/spotifete

EXPOSE 8410

CMD ["/opt/spotifete/spotifete"]

0 comments on commit 0e7491b

Please sign in to comment.