1name: Create Release 2 3on: 4 push: 5 branches: 6 - main 7 - release/* 8 tags: 9 # Final Release tags look like: v1.11.0 10 - v[0-9]+.[0-9]+.[0-9]+ 11 # Release candidate tags look like: v1.11.0-rc1 12 - v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+ 13 release: 14 types: [published] 15 pull_request: 16 paths: [.github/workflows/create_release.yml] 17 18jobs: 19 release: 20 if: ${{ github.repository == 'pytorch/pytorch' }} 21 name: Create Release 22 runs-on: ubuntu-latest 23 # https://github.com/softprops/action-gh-release?tab=readme-ov-file#permissions 24 permissions: 25 contents: write 26 outputs: 27 pt_release_name: ${{ steps.release_name.outputs.pt_release_name }} 28 steps: 29 - uses: malfet/checkout@silent-checkout 30 with: 31 submodules: 'recursive' 32 ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} 33 - name: Fake name for PRs 34 if: ${{ github.event_name == 'pull_request' }} 35 run: echo "PT_GITHUB_REF=refs/tags/pr-tag" >> "$GITHUB_ENV" 36 - name: Real name for non-PRs 37 if: ${{ github.event_name != 'pull_request' }} 38 run: echo "PT_GITHUB_REF=$GITHUB_REF" >> "$GITHUB_ENV" 39 - name: Set filenames 40 run: | 41 tag_or_branch="${PT_GITHUB_REF#refs/tags/}" 42 tag_or_branch="${tag_or_branch#refs/heads/}" 43 # replace directory separators with _ in branch name 44 tag_or_branch="${tag_or_branch//\//_}" 45 echo "PT_RELEASE_NAME=pytorch-$tag_or_branch" >> "$GITHUB_ENV" 46 echo "PT_RELEASE_FILE=pytorch-$tag_or_branch.tar.gz" >> "$GITHUB_ENV" 47 - name: Create source distribution 48 run: | 49 # Create new folder with specified name so extracting the archive yields that 50 rm -rf "/tmp/$PT_RELEASE_NAME" 51 cp -r "$PWD" "/tmp/$PT_RELEASE_NAME" 52 mv "/tmp/$PT_RELEASE_NAME" . 53 # Cleanup 54 rm -rf "$PT_RELEASE_NAME"/{.circleci,.ci} 55 find "$PT_RELEASE_NAME" -name '.git*' -exec rm -rv {} \; || true 56 # Create archive 57 tar -czf "$PT_RELEASE_FILE" "$PT_RELEASE_NAME" 58 echo "Created source archive $PT_RELEASE_FILE with content: $(ls -a "$PT_RELEASE_NAME")" 59 - name: Upload source distribution for release 60 if: ${{ github.event_name == 'release' }} 61 uses: softprops/action-gh-release@v1 62 with: 63 files: ${{env.PT_RELEASE_FILE}} 64 - name: Upload source distribution to GHA artifacts for release tags 65 if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && contains(github.ref, 'rc') }} 66 uses: actions/upload-artifact@v2 67 with: 68 name: ${{ env.PT_RELEASE_FILE }} 69 path: ${{ env.PT_RELEASE_FILE }} 70 - name: Set output 71 id: release_name 72 run: echo "::set-output name=pt_release_name::${{ env.PT_RELEASE_NAME }}.tar.gz" 73 74 upload_source_code_to_s3: 75 if: ${{ github.repository == 'pytorch/pytorch' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && contains(github.ref, 'rc') }} 76 runs-on: linux.2xlarge 77 environment: sourcecode-upload 78 name: Upload source code to S3 for release tags 79 permissions: 80 id-token: write 81 needs: release 82 steps: 83 - uses: actions/download-artifact@v2 84 with: 85 name: ${{ needs.release.outputs.pt_release_name }} 86 - name: Configure AWS credentials(PyTorch account) 87 uses: aws-actions/configure-aws-credentials@v3 88 with: 89 role-to-assume: arn:aws:iam::749337293305:role/gha_pytorch_source_code_upload_role 90 aws-region: us-east-1 91 - uses: seemethere/upload-artifact-s3@v5 92 with: 93 s3-bucket: pytorch 94 s3-prefix: source_code/test 95 if-no-files-found: warn 96 path: ${{ needs.release.outputs.pt_release_name }} 97 98concurrency: 99 group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name }} 100 cancel-in-progress: true 101