Release 0.4.0 #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: Release | |
| on: | |
| push: | |
| branches: [main] | |
| paths: ['RELEASES.md'] | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| if: github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout EWC | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Parse top release section | |
| id: parse | |
| run: | | |
| set -euo pipefail | |
| version=$(awk '/^## \[v[0-9]+\.[0-9]+\.[0-9]+\]/ { | |
| match($0, /v[0-9]+\.[0-9]+\.[0-9]+/) | |
| print substr($0, RSTART, RLENGTH) | |
| exit | |
| }' RELEASES.md) | |
| if [ -z "$version" ]; then | |
| echo "::notice::No versioned section in RELEASES.md (only Unreleased?). Nothing to do." | |
| echo "skip=true" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| awk -v ver="$version" ' | |
| $0 ~ "^## \\[" ver "\\]" { found = 1; next } | |
| /^## / && found { exit } | |
| found { print } | |
| ' RELEASES.md > /tmp/notes.md | |
| echo "version=$version" >> "$GITHUB_OUTPUT" | |
| echo "skip=false" >> "$GITHUB_OUTPUT" | |
| - name: Check if tag already exists | |
| if: steps.parse.outputs.skip != 'true' | |
| id: tag_check | |
| run: | | |
| if git rev-parse "refs/tags/${{ steps.parse.outputs.version }}" >/dev/null 2>&1; then | |
| echo "::notice::Tag ${{ steps.parse.outputs.version }} already exists; nothing to do." | |
| echo "exists=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "exists=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Clone ewc-client | |
| if: steps.parse.outputs.skip != 'true' && steps.tag_check.outputs.exists != 'true' | |
| run: | | |
| git clone --depth=1 https://github.com/dyalog/ewc-client.git /tmp/ewc-client | |
| echo "EWC_CLIENT_SHA=$(git -C /tmp/ewc-client rev-parse --short HEAD)" >> "$GITHUB_ENV" | |
| - name: Refresh client/dist from ewc-client | |
| if: steps.parse.outputs.skip != 'true' && steps.tag_check.outputs.exists != 'true' | |
| id: refresh | |
| run: | | |
| rm -rf client/dist | |
| mkdir -p client | |
| cp -R /tmp/ewc-client/dist client/dist | |
| if git diff --quiet -- client/dist; then | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Commit refreshed dist to main | |
| if: | | |
| steps.parse.outputs.skip != 'true' && | |
| steps.tag_check.outputs.exists != 'true' && | |
| steps.refresh.outputs.changed == 'true' | |
| run: | | |
| set -euo pipefail | |
| version="${{ steps.parse.outputs.version }}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add client/dist | |
| git commit -m "chore(release): $version - refresh client/dist from ewc-client@${EWC_CLIENT_SHA}" | |
| git push origin HEAD:main | |
| - name: Tag and create GitHub Release | |
| if: steps.parse.outputs.skip != 'true' && steps.tag_check.outputs.exists != 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| set -euo pipefail | |
| version="${{ steps.parse.outputs.version }}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag -a "$version" -m "Release $version" | |
| git push origin "$version" | |
| (cd client && zip -r /tmp/client-dist.zip dist) | |
| gh release create "$version" \ | |
| --title "$version" \ | |
| --notes-file /tmp/notes.md \ | |
| /tmp/client-dist.zip |