Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #4 from cisagov/feature/add-release-actions
Browse files Browse the repository at this point in the history
add tags to release.yml
  • Loading branch information
itsmostafa authored Feb 1, 2023
2 parents c89f1e5 + 5d12d6b commit 7b1b5c6
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 21 deletions.
127 changes: 109 additions & 18 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,121 @@ name: release

on:
push:
tags:
- "*" # triggers only if push new tag version
branches:
- develop

env:
RUN_TMATE: ${{ secrets.RUN_TMATE }}

jobs:
build:
name: GoReleaser build
name: go-build
runs-on: ubuntu-latest

strategy:
matrix:
bin:
- pca-linux-amd64
- pca-linux-arm64
- pca-osx-amd64
- pca-osx-arm64
include:
- bin: pca-linux-amd64
goos: linux
arch: amd64
- os: pca-linux-arm64
goos: linux
arch: arm64
- bin: pca-osx-amd64
goos: darwin
arch: amd64
- bin: pca-osx-arm64
goos: darwin
arch: arm64
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- uses: actions/checkout@v3
- id: setup-go
uses: actions/setup-go@v3
with:
fetch-depth: 0 # See: https://goreleaser.com/ci/actions/

- name: Set up go
uses: actions/setup-go@v2
go-version: "1.19"
cache: true
- name: Lookup Go cache directory
id: go-cache
run: |
echo "dir=$(go env GOCACHE)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
env:
BASE_CACHE_KEY: "${{ github.job }}-${{ runner.os }}-\
go${{ steps.setup-go.outputs.go-version }}-"
with:
go-version: 1.19
id: go

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@master
path: |
${{ steps.go-cache.outputs.dir }}
key: "${{ env.BASE_CACHE_KEY }}\
${{ hashFiles('go.mod') }}-\
${{ hashFiles('go.sum') }}"
restore-keys: |
${{ env.BASE_CACHE_KEY }}
- name: Build ${{ matrix.os }}
run: go build -o ${{ matrix.bin }}
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.arch }}
- name: Upload to artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.os }}
path: ${{ matrix.bin }}
release:
name: go-release
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- name: Download to artifacts
uses: actions/download-artifact@v3
with:
path: bin
- name: Set Tag Version
run: echo "VERSION=$(cat ./VERSION)" >> $GITHUB_ENV
- name: Create Release
uses: actions/github-script@v6
with:
version: latest
args: release --rm-dist
github-token: "${{ secrets.GITHUB_TOKEN }}"
script: |
try {
const response = await github.rest.repos.createRelease({
draft: false,
generate_release_notes: true,
name: `con-pca-tasks ${process.env.VERSION}`,
owner: context.repo.owner,
prerelease: false,
repo: context.repo.repo,
tag_name: process.env.VERSION,
});
core.exportVariable('RELEASE_ID', response.data.id);
core.exportVariable('RELEASE_UPLOAD_URL', response.data.upload_url);
} catch (error) {
core.setFailed(error.message);
}
- name: Upload Archives to Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
UPLOAD_URL: ${{ env.RELEASE_UPLOAD_URL }}
API_HEADER: "Accept: application/vnd.github.v3+json"
AUTH_HEADER: "Authorization: token ${{ secrets.GITHUB_TOKEN }}"
run: |
UPLOAD_URL=$(echo -n $UPLOAD_URL | sed s/\{.*//g)
for each in bin/*
do
for FILE in $each/*
do
echo "Uploading ${FILE}";
curl \
-H "${API_HEADER}" \
-H "${AUTH_HEADER}" \
-H "Content-Type: $(file -b --mime-type ${FILE})" \
--data-binary "@${FILE}" \
"${UPLOAD_URL}?name=$(basename ${FILE})";
done
done
- name: Setup tmate debug session
uses: mxschmitt/action-tmate@v3
if: env.RUN_TMATE
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
# Test binary, built with `go test -c`
*.test

## Environment variables ##
.env

## MacOS ##
.DS_Store

## Python ##
__pycache__
.mypy_cache
.python-version
.venv

## Environment variables ##
.env
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.0.1

0 comments on commit 7b1b5c6

Please sign in to comment.