-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from partyoffice/improve-ci
Feature: Improve ci
- Loading branch information
Showing
3 changed files
with
56 additions
and
45 deletions.
There are no files selected for viewing
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
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 | ||
|
@@ -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 | ||
|
@@ -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 |
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
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
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"] |