Skip to content

Commit

Permalink
build: action exit gracefully.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamriajul committed Aug 17, 2023
1 parent d8f99dc commit 74f3f43
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions .github/workflows/create-release-automatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ on:
- cron: '0 10 * * *'

jobs:
build:
find:
runs-on: ubuntu-latest
outputs:
RELEASE_VERSION: ${{ steps.get_tag.outputs.tag }}
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -21,39 +23,43 @@ jobs:
fetch-depth: 0

- name: Get first stable tag (eg v1.0.0) which is not used by this repository
id: get_tag
run: |
for tag in $(git -C agora-token-service tag -l --sort=creatordate | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$'); do
if ! git tag -l | grep -q $tag; then
echo "Found tag $tag"
echo "RELEASE_VERSION=$tag" >> $GITHUB_ENV
echo "tag=$tag" >> "$GITHUB_OUTPUT"
exit 0
fi
done
echo "No tag found"
exit 0
create:
runs-on: ubuntu-latest
needs: find
if: needs.find.outputs.RELEASE_VERSION
steps:
- name: Get Github Release Data
if: env.RELEASE_VERSION
id: release_data
uses: KevinRohn/github-full-release-data@v2
with:
repository: AgoraIO-Community/agora-token-service
version: ${{ env.RELEASE_VERSION }}
version: ${{ needs.find.outputs.RELEASE_VERSION }}
token: ${{ secrets.GITHUB_TOKEN }}
body-markdown-file-path: ./release-content.md

# Using PAT (Personal Access Token) instead of GITHUB_TOKEN because GITHUB_TOKEN doesn't have permission to create release
# And also if we use GITHUB_TOKEN, it will not trigger our other workflow (docker-publish.yml).
# GitHub Actions prevent trigger workflow using GITHUB_TOKEN, to avoid infinite loop.
- name: Create a release
if: env.RELEASE_VERSION
uses: actions/create-release@v1
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
with:
tag_name: ${{ env.RELEASE_VERSION }}
release_name: ${{ env.RELEASE_VERSION }}
tag_name: ${{ needs.find.outputs.RELEASE_VERSION }}
release_name: ${{ needs.find.outputs.RELEASE_VERSION }}
body_path: ./release-content.md
draft: false
prerelease: false
Expand Down

0 comments on commit 74f3f43

Please sign in to comment.