Skip to content

Commit

Permalink
Adding the project base
Browse files Browse the repository at this point in the history
Adding the project base
  • Loading branch information
rohitagg2020 committed Sep 1, 2021
1 parent 1e7c1f2 commit 9b36c7f
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 0 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: goreleaser

on:
pull_request:
push:
tags:
- 'v*'

jobs:
goreleaser:
runs-on: ubuntu-latest
# Set permissions of github token. See https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#permissions
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16.0

- name: Run GoReleaser
# GoReleaser v2.5.0
uses: goreleaser/goreleaser-action@5e15885530fb01d81d1f24e8a6f54ebbd0fed7eb
if: startsWith(github.ref, 'refs/tags/')
with:
version: 0.162.0
args: release --rm-dist --debug
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/github-script@v4
id: get-checksums-from-draft-release
if: startsWith(github.ref, 'refs/tags/')
with:
github-token: ${{secrets.GITHUB_TOKEN}}
result-encoding: string
script: |
var crypto = require('crypto');
const { owner, repo } = context.repo;
// https://docs.github.com/en/rest/reference/repos#list-releases
// https://octokit.github.io/rest.js/v18#repos-list-releases
var releases = await github.repos.listReleases({
owner: owner,
repo: repo
});
var crypto = require('crypto')
var fs = require('fs')
const url = require('url');
const https = require('https');
checksums = {}
for (const r of releases["data"]) {
if (r.draft && `refs/tags/${r.tag_name}` == "${{ github.ref }}") {
for (const asset of r.assets) {
var release_asset = await github.repos.getReleaseAsset({ headers: {accept: `application/octet-stream`}, accept: `application/octet-stream`, owner: owner, repo: repo, asset_id: asset.id });
const hash = crypto.createHash('sha256');
let http_promise = new Promise((resolve, reject) => {
https.get(release_asset.url, (stream) => {
stream.on('data', function (data) {
hash.update(data);
});
stream.on('end', function () {
checksums[asset.name]= hash.digest('hex');
resolve(`${asset.name}`);
});
});
});
await http_promise;
}
}
}
console.log(checksums)
return `${checksums['kapp-darwin-amd64']} ./hello-world-darwin-amd64
${checksums['hello-world-darwin-arm64']} ./hello-world-darwin-arm64
${checksums['hello-world-linux-amd64']} ./hello-world-linux-amd64
${checksums['hello-world-linux-arm64']} ./hello-world-linux-arm64
${checksums['hello-world-windows-amd64.exe']} ./hello-world-windows-amd64.exe`
- name: verify uploaded artifacts
if: startsWith(github.ref, 'refs/tags/')
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: |
set -e -x
VERSION=`echo ${{ github.ref }} | grep -Eo '[0-9].*'`
console.log(VERSION)
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/hello-*
/tmp
/dist

.idea
49 changes: 49 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This is an example .goreleaser.yml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
main: ./main
binary: hello-world-{{ .Os }}-{{ .Arch }}

archives:
- format: binary
name_template: "{{ .Binary }}"
replacements:
darwin: Darwin
linux: Linux
windows: Windows
amd64: x86_64
checksum:
name_template: 'checksums.txt'
algorithm: sha256
disable: false
snapshot:
name_template: "{{ .Tag }}-next"
release:
github:
owner: rohitagg2020
name: hello-world-with-go-releaser-and-github-actions
draft: true
prerelease: auto
name_template: "{{.Tag}}"
disable: false

changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
skip: false
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/rohitagg2020/hello-world-with-go-releaser-and-github-actions

go 1.16
7 changes: 7 additions & 0 deletions main/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "fmt"

func main() {
fmt.Println("Hello World")
}

0 comments on commit 9b36c7f

Please sign in to comment.