Skip to content

Compile and Release on Tag Push #23

Compile and Release on Tag Push

Compile and Release on Tag Push #23

Workflow file for this run

name: "Compile and Release on Tag Push"
on:
push:
tags:
- '*'
workflow_dispatch:
jobs:
build-and-release-tag:
if: github.repository == 'playtechnique/templ'
runs-on: ubuntu-22.04
env:
OUTPUT_BINARY: templ
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: "checkout"
uses: actions/checkout@v3
with:
ref: ${{ env.GITHUB_REF }}
fetch-depth: 0
- name: 'Get Previous tag'
id: previoustag
uses: "WyriHaximus/github-action-get-previous-tag@v1"
- name: "checkout again at tag version"
uses: actions/checkout@v3
with:
ref: ${{ steps.previoustag.outputs.tag }}
- name: show we understand previoustag
run: |
echo "<${{ steps.previoustag.outputs.tag }}>"
- name: 'Check if release already exists'
id: check_release
run: |
RELEASE_URL=$(curl -sH "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.previoustag.outputs.tag }}" \
| jq -r ".url" )
if [[ "$RELEASE_URL" != "null" ]]; then
echo "Release already exists. Skipping..."
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: "compile binary"
if: steps.check_release.outputs.exists == 'false'
run: |
GOOS=linux go build -o ${{ env.OUTPUT_BINARY }}-linux
GOOS=darwin GOARCH=amd64 go build -o ${{ env.OUTPUT_BINARY }}-mac-amd64
GOOS=darwin GOARCH=arm64 go build -o ${{ env.OUTPUT_BINARY }}-mac-arm64
GOOS=windows GOARCH=amd64 go build -o ${{ env.OUTPUT_BINARY }}-win-amd64
- name: Release
if: steps.check_release.outputs.exists == 'false'
id: create_release
uses: actions/create-release@v1
with:
tag_name: ${{ steps.previoustag.outputs.tag }}
release_name: Release ${{ steps.previoustag.outputs.tag }}
- name: Upload linux
if: steps.check_release.outputs.exists == 'false'
id: upload-linux-asset
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./${{ env.OUTPUT_BINARY }}-linux
asset_name: ${{ env.OUTPUT_BINARY }}-linux
asset_content_type: binary
- name: Upload macos amd64
if: steps.check_release.outputs.exists == 'false'
id: upload-macos-asset-amd64
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./${{ env.OUTPUT_BINARY }}-mac-amd64
asset_name: ${{ env.OUTPUT_BINARY }}-mac-amd64
asset_content_type: binary
- name: Upload macos arm64
if: steps.check_release.outputs.exists == 'false'
id: upload-macos-asset-arm64
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./${{ env.OUTPUT_BINARY }}-mac-arm64
asset_name: ${{ env.OUTPUT_BINARY }}-mac-arm64
asset_content_type: binary
- name: Upload windows arm64
if: steps.check_release.outputs.exists == 'false'
id: upload-windows-asset-arm64
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./${{ env.OUTPUT_BINARY }}-win-amd64
asset_name: ${{ env.OUTPUT_BINARY }}-win-amd64
asset_content_type: binary
outputs:
version_tag: ${{ steps.previoustag.outputs.tag }}
release-homebrew:
runs-on: ubuntu-22.04
needs: build-and-release-tag
env:
SOURCE_CODE_URL: https://github.com/${{ github.repository }}/archive/refs/tags/${{ needs.build-and-release-tag.outputs.version_tag }}.tar.gz
steps:
- name: 'Get source code artifact and binary for this version'
run: |
mkdir templ-downloads
cd templ-downloads
curl -LO ${{ env.SOURCE_CODE_URL }}
- name: 'Generate sha256 sum'
id: generate-sha256
run: |
SHA256=$(shasum -a 256 "templ-downloads/templ-${{ needs.build-and-release-tag.outputs.version_tag }}.tar.gz" | awk '{print $1}')
echo "templ sha256 is ${SHA256}"
echo "sha256=$SHA256" >> $GITHUB_OUTPUT
- name: 'Download homebrew-templ'
uses: actions/checkout@v3
with:
repository: 'PlayTechnique/homebrew-templ'
ssh-key: '${{ secrets.HOMEBREWTEMPLSSHKEY }}'
- name: 'show current file system layout'
run: |
ls -ltr
- name: 'Prepare a template file'
run: |
SHA_VALUE=${{ steps.generate-sha256.outputs.sha256 }}
URL_VALUE=${{ env.SOURCE_CODE_URL }}
sed -i "s|sha256.*|sha256: \"$SHA_VALUE\"|" Formula/templ.rb
sed -i "s|url.*|url: \"$URL_VALUE\"|" Formula/templ.rb
- name: "Add new repo file"
run: |
git config --global user.email "[email protected]"
git config --global user.name "Github Bot"
git add Formula/templ.rb
git commit -m "Auto-Updater from templ: updating for ${{ needs.build-and-release-tag.outputs.version_tag }}"
git push