try 82MB #35
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 | |
# | |
# plan | |
# 0) read in current repo the release meta-info (versions.yml) | |
# 1) prepare in current repo the release content (package) | |
# 2) push to remote public web repo the release definition (version, description...) | |
# 3) wait for remote workflow end with success | |
# 4) create a new release draft of public web repo | |
# 5) upload and attach package to the public release | |
# 6) publish draft release | |
# 7) let report release links, and download links | |
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: mySampleTestFile-1.2.3.exe | |
SKIP_PUSH_VERSION_WORKFLOW: true | |
SKIP_PUBLISH: true | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: 0) Read package.json version | |
id: package_version | |
run: | | |
# Extract the version from package.json and store it as an environment variable | |
version=$(jq -r '.version' package.json) | |
expectedVersion="v$version-test" | |
echo "Package version is $version" | |
if [[ "${{ github.ref_name }}" != "$expectedVersion" ]]; then | |
echo "Error: Tag ${{ github.ref_name }} does not match version ${expectedVersion}" | |
exit 1 | |
fi | |
echo "VERSION=$version" >> $GITHUB_ENV | |
# https://github.com/mikefarah/yq?tab=readme-ov-file#github-action | |
- name: Install yq | |
uses: mikefarah/yq@master | |
- name: 0) Read version meta-info from versions.yml to env | |
id: yaml_to_env | |
run: | | |
# Extract data for version ${{ env.VERSION }} from versions.yml | |
version_data=$(yq '.versions[] | select(.version == "${{ env.VERSION }}")' versions.yml) | |
# Check if version_data is empty | |
if [ -z "$version_data" ]; then | |
echo "Error: No data found for version ${{ env.VERSION }} in versions.yml" | |
exit 1 | |
fi | |
######## | |
# Function to extract specific fields and format values | |
######## | |
# Extract and | |
# yq -r '.description' : use yq to extract (-r) raw value (without quotes) | |
# sed ':a;N;$!ba;s/\n/\\n/g; s/\'/’/g' : | |
## :a;N;$!ba; : get all line in a buffer | |
## s/\n/\\n/g : substitute all carriage return by \n. | |
## s/\'/’/g : substitute single quote by typographic quote 0146. | |
extract_value() { | |
echo "$(echo "$version_data" | yq -r "$1" | sed ':a;N;$!ba;s/\n/\\n/g; s/'\''/’/g')" | |
} | |
# and store them in environment variables | |
echo "LABEL=$(extract_value '.label')" >> $GITHUB_ENV | |
echo "LABEL_FR=$(extract_value '.label_fr')" >> $GITHUB_ENV | |
echo "DESCRIPTION=$(extract_value '.description')" >> $GITHUB_ENV | |
echo "DESCRIPTION_FR=$(extract_value '.description_fr')" >> $GITHUB_ENV | |
- name: 1) Prepare release file (Simulation) | |
run: | | |
mkdir -p ./packages | |
head -c 82M </dev/urandom >./packages/$FILE_NAME | |
echo "Preparing release file ./packages/$FILE_NAME done :" | |
ls -lartkh ./packages/ | |
- name: 2) push new release definition to another repo | |
if: ${{ env.SKIP_PUSH_VERSION_WORKFLOW != 'true' }} | |
run: | | |
# Disable -e temporarily to capture the curl exit status manually | |
set +e | |
response=$(curl -sf -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": "${{ env.VERSION }}", | |
"label": "${{ env.LABEL }}", | |
"label_fr": "${{ env.LABEL_FR }}", | |
"description": "${{ env.DESCRIPTION }}", | |
"description_fr": "${{ env.DESCRIPTION_FR }}", | |
"note": "${{ env.REPO_WEB_URL }}/releases/tag/${{ env.VERSION }}", | |
"download": "${{ env.REPO_WEB_URL }}/releases/download/${{ env.VERSION }}/package.readme.txt" | |
} | |
}') | |
# Capture the curl exit status | |
exit_status=$? | |
# Re-enable -e for the rest of the script | |
set -e | |
# Check for errors | |
if [ $exit_status -ne 0 ]; then | |
echo "Error: curl command failed with status $exit_status" | |
exit 1 | |
fi | |
# Output the curl response | |
echo "$response" | |
- name: 3) Waiting for push-new-version workflow completion | |
if: ${{ env.SKIP_PUSH_VERSION_WORKFLOW != 'true' }} | |
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: 4) Create Release Draft 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 -f -s -X POST \ | |
-H "Authorization: token ${{ secrets.PAT_TOKEN }}" \ | |
-H "Content-Type: application/json" \ | |
-d '{ | |
"tag_name": "'${{ github.ref_name }}'", | |
"target_commitish": "main", | |
"name": "${{ env.LABEL}}", | |
"body": "${{ env.DESCRIPTION}}\n\n# ${{ env.LABEL_FR}}\n\n${{ env.DESCRIPTION_FR}}", | |
"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: 5) 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: 6) Publish Draft Release | |
if: ${{ env.SKIP_PUBLISH != 'true' }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} | |
run: | | |
# Convert the draft release to a published release | |
curl -f -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: 7) 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" |