|
| 1 | +name: Promote ONNX Runtime |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + stable_promotion: |
| 7 | + required: true |
| 8 | + type: boolean |
| 9 | + |
| 10 | +jobs: |
| 11 | + promote: |
| 12 | + if: inputs.stable_promotion |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + contents: write |
| 16 | + actions: read |
| 17 | + steps: |
| 18 | + - name: Checkout repository |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Get latest experimental release |
| 22 | + id: get_experimental |
| 23 | + env: |
| 24 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 25 | + run: | |
| 26 | + # Get the latest release (should be experimental) |
| 27 | + latest_release=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \ |
| 28 | + https://api.github.com/repos/${{ github.repository }}/releases \ |
| 29 | + | jq -r '.[0]') |
| 30 | +
|
| 31 | + release_id=$(echo "$latest_release" | jq -r '.id') |
| 32 | + release_tag=$(echo "$latest_release" | jq -r '.tag_name') |
| 33 | +
|
| 34 | + echo "experimental_release_id=$release_id" >> $GITHUB_ENV |
| 35 | + echo "experimental_tag=$release_tag" >> $GITHUB_ENV |
| 36 | + echo "Found experimental release: $release_tag (ID: $release_id)" |
| 37 | +
|
| 38 | + - name: Download experimental artifacts |
| 39 | + env: |
| 40 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 41 | + run: | |
| 42 | + # Download all assets from the experimental release |
| 43 | + mkdir -p stable_artifacts |
| 44 | +
|
| 45 | + assets=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \ |
| 46 | + https://api.github.com/repos/${{ github.repository }}/releases/${{ env.experimental_release_id }}/assets \ |
| 47 | + | jq -r '.[] | .url') |
| 48 | +
|
| 49 | + for asset_url in $assets; do |
| 50 | + asset_name=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" "$asset_url" | jq -r '.name') |
| 51 | + echo "Downloading $asset_name..." |
| 52 | + curl -L -H "Authorization: Bearer $GITHUB_TOKEN" \ |
| 53 | + -H "Accept: application/octet-stream" \ |
| 54 | + "$asset_url" -o "stable_artifacts/$asset_name" |
| 55 | + done |
| 56 | +
|
| 57 | + - name: Create stable release |
| 58 | + env: |
| 59 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 60 | + run: | |
| 61 | + # Create stable tag and release |
| 62 | + stable_tag="stable" |
| 63 | +
|
| 64 | + # Delete existing stable tag/release if it exists |
| 65 | + curl -s -X DELETE \ |
| 66 | + -H "Authorization: Bearer $GITHUB_TOKEN" \ |
| 67 | + "https://api.github.com/repos/${{ github.repository }}/git/refs/tags/$stable_tag" || true |
| 68 | +
|
| 69 | + # Get current commit SHA |
| 70 | + commit_sha=$(git rev-parse HEAD) |
| 71 | +
|
| 72 | + # Create new stable tag |
| 73 | + curl -X POST \ |
| 74 | + -H "Authorization: Bearer $GITHUB_TOKEN" \ |
| 75 | + -H "Accept: application/vnd.github.v3+json" \ |
| 76 | + https://api.github.com/repos/${{ github.repository }}/git/refs \ |
| 77 | + -d "{\"ref\": \"refs/tags/$stable_tag\", \"sha\": \"$commit_sha\"}" |
| 78 | +
|
| 79 | + # Create stable release |
| 80 | + release_response=$(curl -X POST \ |
| 81 | + -H "Authorization: Bearer $GITHUB_TOKEN" \ |
| 82 | + -H "Accept: application/vnd.github.v3+json" \ |
| 83 | + https://api.github.com/repos/${{ github.repository }}/releases \ |
| 84 | + -d "{ |
| 85 | + \"tag_name\": \"$stable_tag\", |
| 86 | + \"name\": \"Stable Release\", |
| 87 | + \"body\": \"Stable ONNX Runtime release promoted from ${{ env.experimental_tag }}\", |
| 88 | + \"draft\": false, |
| 89 | + \"prerelease\": false |
| 90 | + }") |
| 91 | +
|
| 92 | + stable_release_id=$(echo "$release_response" | jq -r '.id') |
| 93 | + echo "stable_release_id=$stable_release_id" >> $GITHUB_ENV |
| 94 | +
|
| 95 | + - name: Upload artifacts to stable release |
| 96 | + env: |
| 97 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 98 | + run: | |
| 99 | + for file in stable_artifacts/*; do |
| 100 | + if [ -f "$file" ]; then |
| 101 | + filename=$(basename "$file") |
| 102 | + echo "Uploading $filename to stable release..." |
| 103 | +
|
| 104 | + curl -X POST \ |
| 105 | + -H "Authorization: Bearer $GITHUB_TOKEN" \ |
| 106 | + -H "Content-Type: application/octet-stream" \ |
| 107 | + --data-binary @"$file" \ |
| 108 | + "https://uploads.github.com/repos/${{ github.repository }}/releases/${{ env.stable_release_id }}/assets?name=$filename" |
| 109 | + fi |
| 110 | + done |
0 commit comments