Update README.md #77
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 | |
| # This Workflow automatically creates a Github Release when new tags are pushed to the repository. | |
| # This is for VisualStudio-Github interaction only. It does not affect script functionality. | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest # runs on the latest version of ubuntu | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 # checks out the repository to the runner | |
| with: | |
| fetch-depth: 0 # need this to get all history for the tag check | |
| # apparently we need this when creating and pushing tags (lame) | |
| - name: Set up Git identity | |
| run: | | |
| git config --global user.name "${{ github.actor }}" | |
| git config --global user.email "${{ github.actor }}@tuscoss.com" | |
| # the version number in the script is being automatically updated | |
| # via a post-commit hook in VS, here we only need to extract it | |
| - name: Extract version from script | |
| id: extract_version | |
| run: | | |
| NEW_VERSION=$(grep -Po '(?<=\$scriptVersion = ")([0-9]+\.[0-9]+\.[0-9]+)' at.ps1) | |
| echo "New version: $NEW_VERSION" | |
| echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
| # check if the tag already exists | |
| - name: Check if tag exists | |
| id: check_tag | |
| run: | | |
| if git rev-parse "v$NEW_VERSION" >/dev/null 2>&1; then | |
| echo "Tag v$NEW_VERSION already exists" | |
| echo "TAG_EXISTS=true" >> $GITHUB_ENV | |
| else | |
| echo "Tag v$NEW_VERSION does not exist" | |
| echo "TAG_EXISTS=false" >> $GITHUB_ENV | |
| fi | |
| # if tag doesn't exist, create it | |
| # if it does, skip to the next step | |
| - name: Create and push tag (if it doesn't exist) | |
| if: env.TAG_EXISTS == 'false' | |
| run: | | |
| git tag -a "v$NEW_VERSION" -m "Release version $NEW_VERSION" | |
| git push origin "v$NEW_VERSION" | |
| # extract release notes from the script .NOTES section | |
| - name: Extract release notes from script | |
| run: | | |
| # Add 4 spaces to the start of the warning so it creates a code block too | |
| WARNING_MESSAGE=" (Make sure to edit the new Config.ps1 file before overwriting the old one.)" | |
| # 1. Capture block. 2. Remove first/last line. | |
| # 3. Regex: Capture leading spaces (\1), match the hyphen/space, replace with just the leading spaces. | |
| RELEASE_NOTES=$(sed -n '/^.NOTES/,/^#>/p' at.ps1 | sed '1d;$d' | sed -E 's/^([[:space:]]*)-[[:space:]]*/\1/') | |
| # Combine them. | |
| FULL_RELEASE_NOTES="$(printf "%s\n\n%s" "$RELEASE_NOTES" "$WARNING_MESSAGE")" | |
| echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV | |
| echo "$FULL_RELEASE_NOTES" >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| # create the zip file for the release | |
| - name: Zip files | |
| run: | | |
| mkdir -p release | |
| cp at.ps1 at-config.ps1 at-setup.ps1 at.png at-wallpaper.ps1 AutoTheme.ps1 LICENSE README.md release/ | |
| zip -r release-v$NEW_VERSION.zip release/ | |
| echo "ZIP_FILE=release-v$NEW_VERSION.zip" >> $GITHUB_ENV | |
| # create the release if tag didn't exist | |
| - name: Create Release | |
| if: env.TAG_EXISTS == 'false' | |
| id: create_release | |
| uses: softprops/action-gh-release@v2 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.PAT_GITHUB }} # ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: v${{ env.NEW_VERSION }} | |
| name: Release v${{ env.NEW_VERSION }} | |
| body: ${{ env.RELEASE_NOTES }} | |
| draft: false | |
| prerelease: false | |
| files: ${{ env.ZIP_FILE }} | |
| token: ${{ secrets.PAT_GITHUB }} # rather than ${{ secrets.GITHUB_TOKEN }} |