Skip to content

Commit

Permalink
Merge pull request #1 from blacknon/develop
Browse files Browse the repository at this point in the history
1st release
  • Loading branch information
blacknon authored Feb 12, 2023
2 parents 68b05b7 + 38e66ef commit a8a962a
Show file tree
Hide file tree
Showing 3 changed files with 234 additions and 0 deletions.
223 changes: 223 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
# Copyright (c) 2021 Blacknon. All rights reserved.
# Use of this source code is governed by an MIT license
# that can be found in the LICENSE file.
# reference:
# - https://motemen.hatenablog.com/entry/2019/11/github-actions-crossbuild-rust
# - https://github.com/motemen/lssh/blob/97d3745dcc8931a1d75217573d5ca60705be632f/.github/workflows/release.yml
# - https://github.com/greymd/teip/blob/master/.github/workflows/release.yml


name: Release Job.

on:
push:
branches:
- master

jobs:
# build rust binary
build:
strategy:
matrix:
include:
- goos: linux
goarch: amd64
os: ubuntu-latest
ext: tar.gz
- goos: linux
goarch: amd64
os: ubuntu-latest
ext: rpm
- goos: linux
goarch: amd64
os: ubuntu-latest
ext: deb
- goos: darwin
goarch: amd64
os: macos-latest
ext: tar.gz
- goos: windows
goarch: amd64
os: windows-latest
ext: zip
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1

- name: Set up Go 1.19
uses: actions/setup-go@v1
with:
go-version: 1.19

- name: Get version
id: package_version
shell: bash
run: |
VERSION="$(go run ./ --version | awk '{print $NF}')"
echo "::set-output name=version::$VERSION"
- name: Build binary
run: |
go build -o snipt.${{ matrix.goos }}_${{ matrix.goarch }} ./
- name: Create package file
if: ${{ (matrix.ext == 'tar.gz') || (matrix.ext == 'rpm') || (matrix.ext == 'deb') }}
run: |
_TAR=snipt_${{ steps.package_version.outputs.version }}_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz
mkdir -p package/bin
mv snipt.${{ matrix.goos }}_${{ matrix.goarch }} package/bin/snipt
## mkdir -p package/man
## cp man/snipt.1 package/man
# cp -r completion package/
## sed -i is not used due to difference between macOS and Linux
perl -i -pe s/___VERSION___/${{ steps.package_version.outputs.version }}/ ./package/.tar2package.yml
## tar czvf "$_TAR" -C "$PWD/package" completion bin man .tar2package.yml
tar czvf "$_TAR" -C "$PWD/package" bin .tar2package.yml
- name: Create package file(Windows)
if: matrix.ext == 'zip'
run: |
mkdir package/bin
move snipt.${{ matrix.goos }}_${{ matrix.goarch }} package/bin/snipt.exe
powershell Compress-Archive package snipt_${{ steps.package_version.outputs.version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip
# use: https://github.com/greymd/tar2package
- name: Build rpm
id: rpm
if: matrix.ext == 'rpm'
run: |
_TAR=snipt_${{ steps.package_version.outputs.version }}_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz
docker run -i "greymd/tar2rpm:1.0.1" < "$_TAR" > snipt_${{ steps.package_version.outputs.version }}_${{ matrix.goos }}_${{ matrix.goarch }}.rpm
echo ::set-output name=sha256::$( sha256sum snipt_${{ steps.package_version.outputs.version }}_${{ matrix.goos }}_${{ matrix.goarch }}.rpm | awk '{print $1}' )
# use: https://github.com/greymd/tar2package
- name: Build deb
id: deb
if: matrix.ext == 'deb'
run: |
_TAR=snipt_${{ steps.package_version.outputs.version }}_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz
docker run -i "greymd/tar2deb:1.0.1" < "$_TAR" > snipt_${{ steps.package_version.outputs.version }}_${{ matrix.goos }}_${{ matrix.goarch }}.deb
echo ::set-output name=sha256::$( sha256sum snipt_${{ steps.package_version.outputs.version }}_${{ matrix.goos }}_${{ matrix.goarch }}.deb | awk '{print $1}' )
- name: README for rpm
if: matrix.ext == 'rpm'
run: |
_TAR=snipt_${{ steps.package_version.outputs.version }}_${{ matrix.goos }}_${{ matrix.goarch }}.rpm
- name: Upload artifact
if: matrix.ext == 'rpm'
uses: actions/upload-artifact@v1
with:
name: build-${{ matrix.goos }}_${{ matrix.goarch }}
path: snipt_${{ steps.package_version.outputs.version }}_${{ matrix.goos }}_${{ matrix.goarch }}.rpm

- name: README for deb
if: matrix.ext == 'deb'
run: |
_TAR=snipt_${{ steps.package_version.outputs.version }}_${{ matrix.goos }}_${{ matrix.goarch }}.deb
- name: Upload artifact
if: matrix.ext == 'deb'
uses: actions/upload-artifact@v1
with:
name: build-${{ matrix.goos }}_${{ matrix.goarch }}
path: snipt_${{ steps.package_version.outputs.version }}_${{ matrix.goos }}_${{ matrix.goarch }}.deb

- name: Upload artifact
if: matrix.ext == 'tar.gz'
uses: actions/upload-artifact@v1
with:
name: build-${{ matrix.goos }}_${{ matrix.goarch }}
path: snipt_${{ steps.package_version.outputs.version }}_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz

- name: Upload artifact
if: matrix.ext == 'zip'
uses: actions/upload-artifact@v1
with:
name: build-${{ matrix.goos }}_${{ matrix.goarch }}
path: snipt_${{ steps.package_version.outputs.version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip

# create package release
create-release:
needs:
- build
runs-on: ubuntu-latest
outputs:
version: ${{ steps.package_version.outputs.version }}
steps:
- uses: actions/checkout@v1

- name: Get version
id: package_version
shell: bash
run: |
VERSION="$(go run ./ --version | awk '{print $NF}')"
echo "::set-output name=version::$VERSION"
- id: create-release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.package_version.outputs.version }}
release_name: Version ${{ steps.package_version.outputs.version }}
draft: true
prerelease: false

- run: |
echo '${{ steps.create-release.outputs.upload_url }}' > release_upload_url.txt
- uses: actions/upload-artifact@v1
with:
name: create-release
path: release_upload_url.txt

upload-release:
strategy:
matrix:
include:
- goos: linux
goarch: amd64
os: ubuntu-latest
ext: tar.gz
- goos: linux
goarch: amd64
os: ubuntu-latest
ext: rpm
- goos: linux
goarch: amd64
os: ubuntu-latest
ext: deb
- goos: darwin
goarch: amd64
os: macos-latest
ext: tar.gz
- goos: windows
goarch: amd64
os: windows-latest
ext: zip

needs: [create-release]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v1
with:
name: create-release

- id: upload-url
run: |
echo "::set-output name=url::$(cat create-release/release_upload_url.txt)"
- uses: actions/download-artifact@v1
with:
name: build-${{ matrix.goos }}_${{ matrix.goarch }}

- uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.upload-url.outputs.url }}
asset_path: ./build-${{ matrix.goos }}_${{ matrix.goarch }}/snipt_${{ needs.create-release.outputs.version }}_${{ matrix.goos }}_${{ matrix.goarch }}.${{ matrix.ext }}
asset_name: snipt_${{ needs.create-release.outputs.version }}_${{ matrix.goos }}_${{ matrix.goarch }}.${{ matrix.ext }}
asset_content_type: application/octet-stream
1 change: 1 addition & 0 deletions client/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (g *GitlabClient) Init(u, token string) (err error) {
// create ctx
g.ctx = context.Background()

// TODO: proxyを設定できるように修正する(↓はテスト時のコードなので少し残しておく)
// Create http client
// h := &http.Client{
// Transport: &http.Transport{
Expand Down
10 changes: 10 additions & 0 deletions package/.tar2package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name : snipt
cmdname : snipt
summary : multiple remote platform snippet-code manager command.
description : multiple remote platform snippet-code manager command.
version : ___VERSION___
changelog : See https://github.com/blacknon/snipt/releases
url : https://github.com/blacknon/snipt
author : blacknon
email : [email protected]
libdir : null

0 comments on commit a8a962a

Please sign in to comment.