Create Release with Test File #3
This file contains hidden or 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: Create Release with Test File | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| create-release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Create test file with 100 A characters | |
| run: | | |
| printf 'A%.0s' {1..100} > test-file.txt | |
| ls -la test-file.txt | |
| echo "File contents:" | |
| cat test-file.txt | |
| - name: Create GitHub Release | |
| id: create_release | |
| run: | | |
| RELEASE_TAG=${GITHUB_REF#refs/tags/} | |
| if [ -z "$RELEASE_TAG" ] || [ "$RELEASE_TAG" = "$GITHUB_REF" ]; then | |
| RELEASE_TAG="v$(date +%Y%m%d-%H%M%S)" | |
| fi | |
| RELEASE_RESPONSE=$(curl -L \ | |
| -X POST \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "X-GitHub-Api-Version: 2022-11-28" \ | |
| https://api.github.com/repos/${{ github.repository }}/releases \ | |
| -d "{ | |
| \"tag_name\": \"$RELEASE_TAG\", | |
| \"target_commitish\": \"${{ github.sha }}\", | |
| \"name\": \"Release $RELEASE_TAG\", | |
| \"body\": \"Automated release with test file containing 100 A characters\", | |
| \"draft\": false, | |
| \"prerelease\": false | |
| }") | |
| echo $RELEASE_RESPONSE | |
| UPLOAD_URL=$(echo "$RELEASE_RESPONSE" | jq -r '.upload_url') | |
| RELEASE_ID=$(echo "$RELEASE_RESPONSE" | jq -r '.id') | |
| echo "upload_url=$UPLOAD_URL" >> $GITHUB_OUTPUT | |
| echo "release_id=$RELEASE_ID" >> $GITHUB_OUTPUT | |
| echo "tag_name=$RELEASE_TAG" >> $GITHUB_OUTPUT | |
| - name: Upload test file as release asset | |
| run: | | |
| curl -L \ | |
| -X POST \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "X-GitHub-Api-Version: 2022-11-28" \ | |
| -H "Content-Type: text/plain" \ | |
| "https://uploads.github.com/repos/AdnaneKhan/TestImmutable/releases/${{ steps.create_release.outputs.release_id }}/assets?name=test-file.txt&label=Test%20File%20with%20100%20A%20characters" \ | |
| --data-binary @test-file.txt | |
| - name: Verify release and asset | |
| run: | | |
| echo "Release created successfully!" | |
| echo "Tag: ${{ steps.create_release.outputs.tag_name }}" | |
| echo "Release ID: ${{ steps.create_release.outputs.release_id }}" | |
| echo "Asset uploaded: test-file.txt" |