Skip to content

Generate Release

Generate Release #1405

name: Generate Release
on:
push:
branches:
- master
schedule:
- cron: "0 0 * * *"
env:
REPO: nugu-linux
REPOSLUG: nugu-developers/nugu-linux
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Get last commit from nugu-developers/nugu-linux
env:
GITHUB_EVENT: ${{ toJson(github.event) }}
run: |
LAST_COMMIT=$(curl -s -H "Authorization: token ${{ secrets.GH_TOKEN }}" -X GET https://api.github.com/repos/${REPOSLUG}/commits/master)
SHA=$(echo $LAST_COMMIT | jq '.sha' -r)
SHORTSHA=$(echo $SHA | cut -c -7)
MSG=$(echo $LAST_COMMIT | jq '.commit.message' -r)
TZ=UTC date
TZ=Asia/Seoul date
echo "event = $GITHUB_EVENT"
echo "event_name = ${{ github.event_name }}"
echo "SHA=$SHA"
echo "SHORTSHA=$SHORTSHA"
echo "MSG=$MSG"
echo "sha=$SHA" >> $GITHUB_ENV
echo "shortsha=$SHORTSHA" >> $GITHUB_ENV
echo "body<<EOF" >> $GITHUB_ENV
echo "$MSG" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Check existing release for ${{ env.shortsha }}
run: |
echo "SHA=${{ env.sha }}"
ID=$(curl -s -H "Authorization: token ${{ secrets.GH_TOKEN }}" -X GET https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/tags/${{ env.shortsha }} | jq '.id' -r)
echo "> Release ID = ${ID}"
if [[ ${ID} != "null" ]]; then
echo "Release ${ID} is already exist"
echo "exist=1" >> $GITHUB_ENV
else
echo "Release ${ID} is not exist."
echo "exist=0" >> $GITHUB_ENV
fi
- name: Done
if: ${{ env.exist == '1'}}
run: echo "Done"
- name: Generate new release
if: ${{ env.exist == '0'}}
run: |
jq -n --arg body "${{ env.body }}" \
--arg tag_name "${{ env.shortsha }}" \
--arg name "${{ env.shortsha }}" \
'{ "tag_name": $tag_name, "name": $name, "body": $body }' | curl -D - \
-H "Authorization: token ${{ secrets.GH_TOKEN }}" \
-X POST https://api.github.com/repos/${GITHUB_REPOSITORY}/releases -d@-