Skip to content

Merge pull request #62 from Privado-Inc/dev #93

Merge pull request #62 from Privado-Inc/dev

Merge pull request #62 from Privado-Inc/dev #93

Workflow file for this run

name: Release Privado CLI
on:
push:
branches:
- main
tags: ["*"]
jobs:
check-release-condition:
name: Check release criteria
runs-on: ubuntu-latest
outputs:
release: ${{ steps.checkRelease.outputs.makeRelease }}
tag: ${{ steps.checkRelease.outputs.releaseTag }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- id: checkRelease
run: |
echo "Testing criteria: > Release if a new tag is pushed to main"
RELEASE_BRANCH="main"
LATEST_TAG=$(git describe --tags --abbrev=0)
LATEST_TAG_SHA=$(git rev-parse $(git describe --tags --abbrev=0))
BRANCH_CONTAINS_LATEST_TAG=$(git branch -a origin/$RELEASE_BRANCH --contains $LATEST_TAG | cat)
LATEST_RELEASED_TAG=$(curl --silent -H "Accept: application/vnd.github+json" -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/${{ github.repository }}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
echo "LATEST_TAG $LATEST_TAG"
echo "BRANCH_CONTAINS $BRANCH_CONTAINS_LATEST_TAG"
echo "LATEST_RELEASED_TAG $LATEST_RELEASED_TAG"
# set default output
echo "::set-output name=releaseTag::$LATEST_TAG"
echo "::set-output name=makeRelease::false"
echo "Check if RELEASE_BRANCH $RELEASE_BRANCH contains latest tag $LATEST_TAG"
if [[ $BRANCH_CONTAINS_LATEST_TAG != "" ]]
then
echo "Found branch to contain LATEST_TAG $LATEST_TAG"
echo "::set-output name=makeRelease::true"
else
echo "Tagged commit not yet part of release branch, skipping.."
fi
echo "Check if tag $LATEST_TAG is already released"
if [[ $LATEST_TAG != "" && $LATEST_RELEASED_TAG == $LATEST_TAG ]]
then
echo "Found latest tag $LATEST_TAG to be already released"
echo "Release criteria failed"
echo "::set-output name=makeRelease::false"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
release:
name: Create Release
runs-on: ubuntu-latest
needs: check-release-condition
if: ${{ needs.check-release-condition.outputs.release == 'true' }}
outputs:
tag: ${{ steps.settag.outputs.tag }}
releaseURL: ${{ steps.create_release.outputs.url }}
steps:
- uses: actions/checkout@v2
- name: Set release tag
id: settag
run: |
echo ${{ needs.check-release-condition.outputs.release }}
PRIVADO_RELEASE_TAG=${{ needs.check-release-condition.outputs.tag }}
# any additional changes to tag from criteria ti be done here
echo "Final Tag: $PRIVADO_RELEASE_TAG"
echo "PRIVADO_RELEASE_TAG=$(echo -n $PRIVADO_RELEASE_TAG)" >> $GITHUB_ENV
echo "::set-output name=tag::$PRIVADO_RELEASE_TAG"
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.PRIVADO_RELEASE_TAG }}
name: Privado CLI ${{ env.PRIVADO_RELEASE_TAG }}
generate_release_notes: true
draft: false
prerelease: false
files: |
README.md
install.sh
release-assets:
name: Attach Release Assets
runs-on: ubuntu-20.04
needs: release
strategy:
matrix:
# build and publish in parallel: linux/amd64
goos: [linux, windows, darwin]
goarch: [amd64, arm64]
exclude:
- goarch: arm64
goos: windows
steps:
- uses: actions/checkout@v2
- uses: wangyoucao577/[email protected]
with:
release_tag: ${{ needs.release.outputs.tag }}
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
project_path: "./"
binary_name: "privado"
goversion: "https://dl.google.com/go/go1.18.4.linux-amd64.tar.gz"
asset_name: privado-${{ matrix.goos }}-${{ matrix.goarch }}
overwrite: true
ldflags: "-X 'github.com/Privado-Inc/privado-cli/cmd.Version=${{ needs.release.outputs.tag }}'"
- run: echo "Release Successful > ${{ needs.release.outputs.releaseURL }}"