Update prerelease.yml #40
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release Pre-release | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
release: | |
name: Release Pre-release | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '16.x' | |
- name: Install jq | |
run: sudo apt-get install -y jq | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Get Version From Package.json | |
id: get-version | |
uses: beaconbrigade/[email protected] | |
with: | |
path: . | |
- name: Create release zip | |
run: zip -r "V${{ steps.get-version.outputs.version }}-prerelease.zip" . -x "*.git*" ".github*" ".gitignore" | |
- name: Check if release exists | |
id: check_release | |
run: | | |
set -e | |
response=$(curl -s -o /dev/null -w "%{http_code}" -X GET -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/releases/tags/v${{ steps.get-version.outputs.version }}") | |
if [[ $response -eq 200 ]]; then | |
echo "Release v${{ steps.get-version.outputs.version }}" exists. | |
echo "RELEASE_EXISTS=true" >> $GITHUB_ENV | |
else | |
echo "Release v${{ steps.get-version.outputs.version }}" does not exist. | |
echo "RELEASE_EXISTS=false" >> $GITHUB_ENV | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create or update GitHub Release | |
id: create_or_update_github_release | |
uses: actions/create-release@v1 | |
with: | |
tag_name: "V${{ steps.get-version.outputs.version }}" | |
release_name: "Pre-release ${{ steps.get-version.outputs.version }}" | |
draft: false | |
prerelease: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
if: env.RELEASE_EXISTS != 'true' | |
- name: Get Release ID | |
if: env.RELEASE_EXISTS == 'true' | |
id: get_release_id | |
run: | | |
set -e | |
release_id=$(curl -s -X GET -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/releases/tags/v${{ steps.get-version.outputs.version }}" | jq -r '.id') | |
echo "RELEASE_ID=$release_id" >> $GITHUB_ENV | |
- name: Upload release artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: "V${{ steps.get-version.outputs.version }}-prerelease" | |
path: "V${{ steps.get-version.outputs.version }}-prerelease.zip" | |
- name: Attach artifact to release | |
if: env.RELEASE_EXISTS == 'true' | |
run: | | |
set -e | |
curl -X POST -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "Content-Type: application/zip" --data-binary @V${{ steps.get-version.outputs.version }}-prerelease.zip "https://uploads.github.com/repos/${{ github.repository }}/releases/${{ env.RELEASE_ID }}/assets?name=V${{ steps.get-version.outputs.version }}-prerelease.zip" |