Browse Source

Add github action to make release

Thomas Dy 4 years ago
parent
commit
88de0e5181
2 changed files with 17 additions and 8 deletions
  1. 6 0
      .github/workflows/build.yaml
  2. 11 8
      scripts/make-release.sh

+ 6 - 0
.github/workflows/build.yaml

@@ -14,3 +14,9 @@ jobs:
           node-version: '14'
       - run: npm install
       - run: npm run build
+
+      - name: Make Release
+        if: startsWith(github.ref, 'refs/tags/')
+        run: scripts/make-release.sh
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

+ 11 - 8
scripts/make-release.sh

@@ -2,13 +2,16 @@
 
 set -euo pipefail
 
-version=$(jq -r .version package.json)
-release_name="typingfreaks-v$version"
-
-# if git ls-remote --tags --exit-code origin "v$version"; then
-#     echo "Release $release_name already exists"
-#     exit 1
-# fi
+if [[ "${GITHUB_REF:-}" == refs/tags/* ]]; then
+    version=${GITHUB_REF/refs\/tags\//}
+else
+    version="v$(jq -r .version package.json)"
+    if git ls-remote --tags --exit-code origin "$version"; then
+        echo "Release $release_name already exists"
+        exit 1
+    fi
+fi
+release_name="typingfreaks-$version"
 
 npm run build
 
@@ -26,4 +29,4 @@ for file in $(git ls-files dist); do
 done
 zip -r "$release_name.zip" "$release_name"
 
-gh release create -d --notes "" "v$version" "$release_name.zip"
+gh release create -d --notes "" "$version" "$release_name.zip"