Skip to content

Commit 0e7491b

Browse files
authored
Merge pull request #72 from partyoffice/improve-ci
Feature: Improve ci
2 parents 096aa05 + 83a8592 commit 0e7491b

File tree

3 files changed

+56
-45
lines changed

3 files changed

+56
-45
lines changed

.github/workflows/release.yml

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,55 @@
11
name: Release
22

33
on:
4-
workflow_dispatch:
5-
inputs:
6-
version:
7-
description: 'The version number of the release'
8-
required: true
4+
push:
5+
branches:
6+
- master
97

108
jobs:
119
release:
1210
runs-on: ubuntu-latest
1311

1412
steps:
15-
- name: Merge develop into master
16-
uses: everlytic/branch-merge@1.1.0
17-
with:
18-
github_token: ${{ github.token }}
19-
source_ref: 'develop'
20-
target_branch: 'master'
21-
commit_message_template: 'Release v${{ github.event.inputs.version }}'
22-
23-
- name: Checkout master
13+
- name: Checkout # Don't use actions/checkout@v2 because we need the tags
2414
run: |
2515
git clone https://github.com/partyoffice/spotifete.git ./
2616
git checkout -f master
27-
28-
- name: Create release tag
29-
run: |
30-
git tag v${{ github.event.inputs.version }}
31-
git push https://Nikos410:${{ secrets.GITHUB_TOKEN }}@github.com/partyoffice/spotifete.git v${{ github.event.inputs.version }}
3217
33-
- name: Merge master back into develop
18+
- name: Get merged pull request
19+
id: merged-pr
20+
uses: remihq/action-get-merged-pull-request@v1
21+
with:
22+
github_token: ${{ github.token }}
23+
24+
- name: Set release version
25+
id: release-version
26+
env:
27+
PR_TITLE: ${{ steps.merged-pr.outputs.title }}
28+
PR_LABELS: ${{ steps.merged-pr.outputs.labels }}
3429
run: |
35-
git checkout -f develop
36-
git merge --ff-only master
37-
git push https://Nikos410:${{ secrets.GITHUB_TOKEN }}@github.com/partyoffice/spotifete.git develop
30+
VERSION_TAG=$(git describe --tags)
31+
VERSION_MAJOR=$(echo $VERSION_TAG | sed -r 's/[^0-9]*([0-9]+)[.]([0-9]+)[.]([0-9])+.*/\1/')
32+
VERSION_MINOR=$(echo $VERSION_TAG | sed -r 's/[^0-9]*([0-9]+)[.]([0-9]+)[.]([0-9])+.*/\2/')
33+
VERSION_PATCH=$(echo $VERSION_TAG | sed -r 's/[^0-9]*([0-9]+)[.]([0-9]+)[.]([0-9])+.*/\3/')
3834
39-
- name: Set up Go
40-
uses: actions/setup-go@v2
41-
with:
42-
go-version: 1.17
35+
if [[ $PR_TITLE = Feature:* ]] || [[ $PR_LABELS = *Feature* ]]
36+
then
37+
RELEASE_VERSION_MAJOR=$VERSION_MAJOR
38+
RELEASE_VERSION_MINOR=$((VERSION_MINOR+1))
39+
RELEASE_VERSION_PATCH=0
40+
else
41+
RELEASE_VERSION_MAJOR=$VERSION_MAJOR
42+
RELEASE_VERSION_MINOR=$VERSION_MINOR
43+
RELEASE_VERSION_PATCH=$((VERSION_PATCH+1))
44+
fi
4345
44-
- name: Build executable
45-
run: CGO_ENABLED=0 go build -v -o ./ ./...
46+
RELEASE_VERSION=$RELEASE_VERSION_MAJOR.$RELEASE_VERSION_MINOR.$RELEASE_VERSION_PATCH
47+
echo "::set-output name=release_version::$RELEASE_VERSION"
48+
49+
- name: Create release tag
50+
run: |
51+
git tag v${{ steps.release-version.outputs.release_version }}
52+
git push https://Nikos410:${{ secrets.GITHUB_TOKEN }}@github.com/partyoffice/spotifete.git v${{ steps.release-version.outputs.release_version }}
4653
4754
- name: Login to Docker Hub
4855
uses: docker/login-action@v1
@@ -61,22 +68,22 @@ jobs:
6168
context: ./
6269
file: ./Dockerfile
6370
push: true
64-
tags: nikos410/spotifete:${{ github.event.inputs.version }}
71+
tags: nikos410/spotifete:${{ steps.release-version.outputs.release_version }},nikos410/spotifete:latest
6572

6673
- name: Publish release
6774
id: publish-release
6875
uses: actions/create-release@v1
6976
env:
7077
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7178
with:
72-
tag_name: v${{ github.event.inputs.version }}
73-
release_name: Release v${{ github.event.inputs.version }}
74-
body: 'Release v${{ github.event.inputs.version }}'
79+
tag_name: v${{ steps.release-version.outputs.release_version }}
80+
release_name: Release v${{ steps.release-version.outputs.release_version }}
81+
body: ${{ steps.merged-pr.outputs.title }}
7582
draft: false
7683
prerelease: false
7784

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

8188
- name: Upload Release Asset
8289
id: upload-release-asset
@@ -85,6 +92,6 @@ jobs:
8592
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8693
with:
8794
upload_url: ${{ steps.publish-release.outputs.upload_url }}
88-
asset_path: spotifete-v${{ github.event.inputs.version }}.tar.gz
89-
asset_name: spotifete-v${{ github.event.inputs.version }}.tar.gz
95+
asset_path: spotifete-v${{ steps.release-version.outputs.release_version }}.tar.gz
96+
asset_name: spotifete-v${{ steps.release-version.outputs.release_version }}.tar.gz
9097
asset_content_type: application/gzip
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
name: Build
1+
name: Test
22

33
on:
4-
push:
54
pull_request:
65

76
jobs:
8-
build:
7+
test:
98
runs-on: ubuntu-latest
109

1110
steps:
12-
- name: Checkout code
11+
- name: Checkout
1312
uses: actions/checkout@v2
1413

1514
- name: Set up Go

Dockerfile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
FROM alpine:3.14
1+
FROM golang:1.17-alpine AS builder
22

3-
WORKDIR /opt/spotifete
3+
WORKDIR /go/src/github.com/partyoffice/spotifete
4+
COPY . .
5+
6+
ENV CGO_ENABLED=0
7+
RUN go build -v -trimpath -o ./ ./...
48

5-
COPY ./spotifete /opt/spotifete/spotifete
6-
COPY ./resources /opt/spotifete/resources
9+
FROM alpine:latest
710

11+
WORKDIR /opt/spotifete
12+
13+
COPY --from=builder /go/src/github.com/partyoffice/spotifete ./
814
RUN chmod +x /opt/spotifete/spotifete
915

1016
EXPOSE 8410
11-
1217
CMD ["/opt/spotifete/spotifete"]

0 commit comments

Comments
 (0)