Skip to content

Commit

Permalink
conditional steps
Browse files Browse the repository at this point in the history
  • Loading branch information
proton committed Nov 27, 2023
1 parent 358d1ac commit ac70465
Showing 1 changed file with 45 additions and 30 deletions.
75 changes: 45 additions & 30 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

name: Create GitHub Release

on:
Expand All @@ -7,7 +8,7 @@ on:
- github-release

jobs:
release:
check_tag:
runs-on: ubuntu-latest

steps:
Expand All @@ -20,33 +21,47 @@ jobs:
VERSION=$(grep 'version"' package.json | cut -d '"' -f 4)
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Create tag
uses: actions/github-script@v7
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ steps.extract_version.outputs.version }}',
sha: context.sha
})
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm install

- name: Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.extract_version.outputs.version }}
files: |
out/Kino.pub_${{ steps.extract_version.outputs.version }}.zip
- name: Publish Release URL
- name: Check if the tag exists
id: check_tag
run: |
echo "Release URL: ${{ steps.create_release.outputs.upload_url }}"
if git rev-parse --quiet --verify "refs/tags/${{ steps.extract_version.outputs.version }}" >/dev/null; then
echo "The tag ${{ steps.extract_version.outputs.version }} exists. Workflow will be canceled."
echo "version_exists=true" >> $GITHUB_OUTPUT
else
echo "The tag ${{ steps.extract_version.outputs.version }} does not exist."
echo "version_exists=false" >> $GITHUB_OUTPUT
fi
- name: Tag and release
if: ${{ needs.check_tag.outputs.tag_exists == 'false' }}
steps:
- name: Create tag
uses: actions/github-script@v7
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ steps.extract_version.outputs.version }}',
sha: context.sha
})
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm install

- name: Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.extract_version.outputs.version }}
files: |
out/Kino.pub_${{ steps.extract_version.outputs.version }}.zip
- name: Publish Release URL
run: |
echo "Release URL: ${{ steps.create_release.outputs.upload_url }}"

0 comments on commit ac70465

Please sign in to comment.