add emoji #18
Workflow file for this run
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: Publish to Public Repo Release | |
on: | |
push: | |
tags: | |
- 'v*.*.*' | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
env: | |
REPO_WEB_URL: https://github.com/chickarmy/chickenbot-web | |
REPO_API_URL: https://api.github.com/repos/chickarmy/chickenbot-web | |
FILE_NAME: package.readme.txt | |
SKIP_PUBLISH: false | |
steps: | |
- name: Checkout private repo | |
uses: actions/checkout@v3 | |
- name: Prepare release file | |
run: | | |
echo 'this is sample publish from private repo' > $FILE_NAME | |
mkdir -p ./packages | |
mv $FILE_NAME ./packages/ | |
echo "Preparing file for release" | |
- name: chickenbot-web trigger push-new-version workflow | |
run: | | |
curl -X POST \ | |
-H "Authorization: token ${{ secrets.PAT_TOKEN }}" \ | |
-H "Accept: application/vnd.github.everest-preview+json" \ | |
${{ env.REPO_API_URL }}/dispatches \ | |
-d '{ | |
"event_type": "push-new-version", | |
"client_payload": { | |
"version": "${{ github.ref_name }}", | |
"label": "release ${{ github.ref_name }}", | |
"label_fr": "release ${{ github.ref_name }}", | |
"description": "This is the TEST description", | |
"description_fr": "Ceci est la description TEST", | |
"note": "${{ env.REPO_WEB_URL }}/releases/tag/${{ github.ref_name }}", | |
"download": "${{ env.REPO_WEB_URL }}/releases/download/${{ github.ref_name }}/package.readme.txt" | |
} | |
}' | |
- name: Waiting for push-new-version workflow completion | |
id: wait_for_completion | |
run: | | |
# Wait and check the status of the triggered workflow | |
workflow="push-new-version" | |
token="${{ secrets.PAT_TOKEN }}" | |
run_id="" | |
# Poll for the workflow run ID of the triggered workflow | |
until [ -n "$run_id" ]; do | |
curl -s \ | |
-H "Authorization: token $token" \ | |
"${{ env.REPO_API_URL }}/actions/runs?event=repository_dispatch&status=in_progress" \ | |
> curl_response | |
cat curl_response | |
run_id=$(jq -r ".workflow_runs[] | select(.display_title==\"push-new-version\") | .id" < curl_response) | |
[ -n "$run_id" ] || echo "Waiting for workflow run ID..." | |
[ -n "$run_id" ] || sleep 3 | |
done | |
echo "ℹ️ Workflow ID: $run_id" | |
# Poll for the workflow status until it's completed | |
conclusion="" | |
until [ "$conclusion" == "success" ]; do | |
conclusion=$(curl -s \ | |
-H "Authorization: token $token" \ | |
"${{ env.REPO_API_URL }}/actions/runs/$run_id" \ | |
| jq -r ".conclusion") | |
if [ "$conclusion" == "failure" ]; then | |
echo " 🔴 The workflow FAILED." | |
exit 1 | |
elif [ "$conclusion" == "cancelled" ]; then | |
echo " 🚫 The workflow was CANCELLED." | |
exit 1 | |
fi | |
echo "Waiting for the workflow to complete..." | |
sleep 10 | |
done | |
echo " ✅ Workflow completed successfully." | |
- name: Create Release in Public Repo | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} | |
run: | | |
RESPONSE_FILE="release_response.json" | |
# Create the release and save the response in a file | |
curl -s -X POST \ | |
-H "Authorization: token ${{ secrets.PAT_TOKEN }}" \ | |
-H "Content-Type: application/json" \ | |
-d '{ | |
"tag_name": "'${{ github.ref_name }}'", | |
"target_commitish": "main", | |
"name": "'${{ github.ref_name }}'", | |
"body": "Release from private repo", | |
"draft": true, | |
"prerelease": false | |
}' \ | |
${{ env.REPO_API_URL }}/releases > $RESPONSE_FILE | |
# Display the API response | |
echo "Release creation response:" | |
cat $RESPONSE_FILE | |
# Extract the release ID from the response file | |
RELEASE_ID=$(jq -r '.id' $RESPONSE_FILE) | |
RELEASE_UPLOAD_URL=$(jq -r '.upload_url' $RESPONSE_FILE) | |
if [ "$RELEASE_ID" == "null" ]; then | |
echo "Failed to create release: $(cat $RESPONSE_FILE)" | |
exit 1 | |
fi | |
echo "Release created successfully! id: $RELEASE_ID - upload_url: $RELEASE_UPLOAD_URL" | |
echo "RELEASE_ID=$RELEASE_ID" >> $GITHUB_ENV | |
echo "RELEASE_UPLOAD_URL=$RELEASE_UPLOAD_URL" >> $GITHUB_ENV | |
# rely on @actions/github NodeJS library | |
## original action - WARN: archived repository | |
## uses: actions/upload-release-asset@v1 | |
## https://github.com/actions/upload-release-asset/blob/main/src/upload-release-asset.js | |
- name: Upload Release Asset | |
id: upload-release-asset | |
# more recent fork node16 @v1.1.1 => @main WARN about changes | |
uses: sekwah41/upload-release-assets@main | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} | |
with: | |
upload_url: ${{ env.RELEASE_UPLOAD_URL }} | |
asset_path: ./packages/${{ env.FILE_NAME }} | |
asset_name: ${{ env.FILE_NAME }} | |
asset_content_type: text/plain | |
- name: Publish Draft Release | |
if: ${{ env.SKIP_PUBLISH != 'true' }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} | |
run: | | |
# Convert the draft release to a published release | |
curl -s -X PATCH \ | |
-H "Authorization: token ${{ secrets.PAT_TOKEN }}" \ | |
-H "Content-Type: application/json" \ | |
-d '{"draft": false}' \ | |
${{ env.REPO_API_URL }}/releases/${{ env.RELEASE_ID }} | |
## WARN : links are ok only when release is published | |
- name: Echo published release and download links | |
if: ${{ env.SKIP_PUBLISH != 'true' }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} | |
run: | | |
RELEASE_URL="${{ env.REPO_WEB_URL }}/releases/tag/${{ github.ref_name }}" | |
DOWNLOAD_URL="${{ env.REPO_WEB_URL }}/releases/download/${{ github.ref_name }}/package.readme.txt" | |
echo "Release page: $RELEASE_URL" | |
echo "Direct download link: $DOWNLOAD_URL" |