Create Release #23
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
# modified from https://github.com/pytorch/pytorch/blob/main/.github/workflows/create_release.yml | |
name: Create Release | |
on: | |
push: | |
tags: | |
- "v*" | |
release: | |
types: [published] | |
pull_request: | |
paths: [.github/workflows/create_release.yml] | |
jobs: | |
release: | |
if: ${{ github.repository == 'obenno/StarScope' }} | |
name: Create Release | |
runs-on: ubuntu-latest | |
# https://github.com/softprops/action-gh-release?tab=readme-ov-file#permissions | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: 'recursive' | |
lfs: true | |
fetch-tags: true | |
fetch-depth: 0 | |
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} | |
- name: Fake name for PRs | |
if: ${{ github.event_name == 'pull_request' }} | |
run: echo "SC_GITHUB_REF=refs/tags/pr-tag" >> "$GITHUB_ENV" | |
- name: Real name for non-PRs | |
if: ${{ github.event_name != 'pull_request' }} | |
run: echo "SC_GITHUB_REF=$GITHUB_REF" >> "$GITHUB_ENV" | |
- name: Set filenames | |
run: | | |
tag_or_branch="${SC_GITHUB_REF#refs/tags/}" | |
tag_or_branch="${tag_or_branch#refs/heads/}" | |
# replace directory separators with _ in branch name | |
tag_or_branch="${tag_or_branch//\//_}" | |
echo "SC_RELEASE_NAME=starscope-$tag_or_branch" >> "$GITHUB_ENV" | |
echo "SC_RELEASE_FILE=starscope-$tag_or_branch.tar.gz" >> "$GITHUB_ENV" | |
echo "TAG_OR_BRANCH=$tag_or_branch" >> "$GITHUB_ENV" | |
- name: Create source distribution | |
run: | | |
# Create new folder with specified name so extracting the archive yields that | |
rm -rf "/tmp/$SC_RELEASE_NAME" | |
cp -r "$PWD" "/tmp/$SC_RELEASE_NAME" | |
mv "/tmp/$SC_RELEASE_NAME" . | |
# Create archive | |
# Modified from https://minhajuddin.com/2016/01/10/how-to-get-a-git-archive-including-submodules/ | |
# original author: Khaja Minhajuddin | |
export ROOT_ARCHIVE_DIR="$(pwd)" | |
git archive --verbose --prefix "starscope/" --format "tar" --output "$ROOT_ARCHIVE_DIR/repo-output.tar" "${TAG_OR_BRANCH#refs/tags/}" | |
git submodule foreach --recursive 'git archive --verbose --prefix=starscope/$path/ --format tar main --output $ROOT_ARCHIVE_DIR/repo-output-sub-$sha1.tar' | |
if [[ $(ls repo-output-sub*.tar | wc -l) != 0 ]] | |
then | |
for file in repo-output-sub*.tar | |
do | |
# combine all archives into one tar | |
tar --concatenate --file repo-output.tar $file | |
done | |
# remove sub tars | |
rm -rf repo-output-sub*.tar | |
fi | |
echo "> gzipping final tar" | |
gzip --force --verbose repo-output.tar | |
echo "> moving output file to $SC_RELEASE_FILE" | |
mv repo-output.tar.gz $SC_RELEASE_FILE | |
echo "Created source archive $SC_RELEASE_FILE with content: $(ls -a "$SC_RELEASE_NAME")" | |
- name: Upload source distribution | |
if: ${{ github.event_name == 'release' }} | |
uses: softprops/action-gh-release@v2 | |
with: | |
files: ${{env.SC_RELEASE_FILE}} |