Release #35
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
name: Release | |
defaults: | |
run: | |
shell: bash | |
permissions: | |
contents: write | |
pull-requests: write | |
on: | |
workflow_run: | |
workflows: [CI] | |
types: [completed] | |
branches: [main] | |
jobs: | |
check_commit: | |
name: Check Commit | |
runs-on: ubuntu-latest | |
outputs: | |
IS_RELEASE: ${{ steps.check_msg.outputs.IS_RELEASE }} | |
LATEST_COMMIT_MSG: ${{ steps.check_msg.outputs.LATEST_COMMIT_MSG }} | |
steps: | |
- name: Check out Git repository | |
uses: actions/checkout@v4 | |
- name: Check latest commit message | |
id: check_msg | |
run: | | |
LATEST_COMMIT_MSG=$(git log -1 --pretty=%B | cat) | |
if [[ ${LATEST_COMMIT_MSG} == *"[release]"* ]]; then | |
echo "release message found - continuing with the release" | |
IS_RELEASE="true" | |
else | |
echo "no release message found - skipping..." | |
IS_RELEASE="false" | |
fi | |
echo "IS_RELEASE=${IS_RELEASE}" >> $GITHUB_OUTPUT | |
release: | |
name: Release | |
needs: [check_commit] | |
runs-on: ubuntu-latest | |
if: ${{ needs.check_commit.outputs.IS_RELEASE == 'true' }} | |
env: | |
IS_RELEASE: ${{ needs.check_commit.outputs.IS_RELEASE }} | |
steps: | |
- name: Check out Git repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Download artifact | |
id: download-artifact | |
uses: dawidd6/action-download-artifact@v6 | |
with: | |
github_token: ${{secrets.GITHUB_TOKEN}} | |
workflow: ci.yml | |
workflow_conclusion: success | |
name: wasm-file | |
- name: Bump version | |
run: | | |
set -e | |
LATEST_COMMIT_MSG=$(git log -1 --pretty=%B | cat) | |
echo "Extract the latest tag version" | |
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1)) | |
BUMP_TYPE="patch" # Initialize the default version bump type to patch | |
if [[ "${LATEST_COMMIT_MSG}" == *"[major]"* ]]; then | |
BUMP_TYPE="major" | |
elif [[ "${LATEST_COMMIT_MSG}" == *"[minor]"* ]]; then | |
BUMP_TYPE="minor" | |
fi | |
case ${BUMP_TYPE} in | |
"major") | |
NEW_TAG=$(echo "${LATEST_TAG}" | awk -F. '{OFS="."; $1="v" substr($1,2)+1; $2="0"; $3="0"; print}') | |
;; | |
"minor") | |
NEW_TAG=$(echo "${LATEST_TAG}" | awk -F. '{OFS="."; $2=$2+1; $3="0"; print}') | |
;; | |
"patch") | |
NEW_TAG=$(echo "${LATEST_TAG}" | awk -F. '{OFS="."; $3=$3+1; print}') | |
;; | |
esac | |
echo "LATEST_TAG=${LATEST_TAG}" >> $GITHUB_ENV | |
echo "NEW_TAG=${NEW_TAG}" >> $GITHUB_ENV | |
- name: Push tag | |
run: | | |
NEW_TAG=${{ env.NEW_TAG }} | |
git tag ${NEW_TAG} | |
git push origin ${NEW_TAG} | |
- name: Calculate sha256 | |
run: | | |
SHA256_HASH=$(sha256sum plugin.wasm | awk '{ print $1 }') | |
echo "SHA256_HASH=${SHA256_HASH}" >> $GITHUB_ENV | |
echo "The calculated sha256 is $SHA256_HASH" | |
- name: Create release draft | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
set -e | |
LATEST_TAG=${{ env.LATEST_TAG }} | |
NEW_TAG=${{ env.NEW_TAG }} | |
SHA256_HASH=${{ env.SHA256_HASH }} | |
CHANGE_LOG=$(git --no-pager log ${LATEST_TAG}..HEAD --pretty=format:'%h - %an, %ar : %s') | |
# Define the release notes template | |
RELEASE_NOTES=$(cat <<EOF | |
## Release version ${NEW_TAG} | |
Release sha256 is \`${SHA256_HASH}\` | |
## Configuration example | |
\`\`\`yaml | |
version: '2' | |
plugins: | |
- name: ruby | |
wasm: | |
url: https://github.com/DaredevilOSS/sqlc-gen-ruby/releases/download/${NEW_TAG}/sqlc-gen-ruby.wasm | |
sha256: ${SHA256_HASH} | |
\`\`\` | |
## Changelog | |
${CHANGE_LOG} | |
## Contributors | |
* @SockworkOrange | |
EOF | |
) | |
# change file name to convention | |
mv plugin.wasm sqlc-gen-ruby.wasm | |
# Create a draft release | |
gh release create ${NEW_TAG} sqlc-gen-ruby.wasm \ | |
--draft \ | |
--title "${NEW_TAG}" \ | |
--notes "${RELEASE_NOTES}" |