diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml new file mode 100644 index 00000000..8d6677b5 --- /dev/null +++ b/.github/workflows/create_release.yml @@ -0,0 +1,55 @@ +name: Create Release + +on: + push: + tags: ['*'] + branches: + - master + release: + types: [published] + pull_request: + paths: [.github/workflows/create_release.yml] + +jobs: + release: + if: ${{ github.repository == 'PhilInTheGaps/GM-Companion' }} + name: Create Release + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + with: + submodules: "recursive" + - name: Fake name for PRs + if: ${{ github.event_name == 'pull_request' }} + run: echo "GM_GITHUB_REF=refs/tags/pr-tag" >> "$GITHUB_ENV" + - name: Real name for non-PRs + if: ${{ github.event_name != 'pull_request' }} + run: echo "GM_GITHUB_REF=$GITHUB_REF" >> "$GITHUB_ENV" + - name: Set filenames + run: | + tag_or_branch="${GM_GITHUB_REF#refs/tags/}" + tag_or_branch="${tag_or_branch#refs/heads/}" + echo "GM_RELEASE_NAME=gm-companion_$tag_or_branch" >> "$GITHUB_ENV" + echo "GM_RELEASE_FILE=companion_$tag_or_branch.tar.gz" >> "$GITHUB_ENV" + - name: Create source distribution + run: | + # Create new folder with specified name so extracting the archive yields that + rm -rf "/tmp/$GM_RELEASE_NAME" + cp -r "$PWD" "/tmp/$GM_RELEASE_NAME" + mv "/tmp/$GM_RELEASE_NAME" . + # Cleanup + rm -rf "$GM_RELEASE_NAME"/{.circleci,.ci} + find "$GM_RELEASE_NAME" -name '.git*' -exec rm -rv {} \; || true + # Create archive + tar -czf "$GM_RELEASE_FILE" "$GM_RELEASE_NAME" + echo "Created source archive $GM_RELEASE_FILE with content: $(ls -a "$GM_RELEASE_NAME")" + - name: Upload source distribution + if: ${{ github.event_name == 'release' }} + uses: softprops/action-gh-release@v1 + with: + files: ${{env.GM_RELEASE_FILE}} + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }} + cancel-in-progress: true \ No newline at end of file