diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..27801fa --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,81 @@ +name: CI + +on: + push: + branches: + - main + +jobs: + Release: + name: Release + runs-on: ubuntu-latest + permissions: + contents: write + + env: + CHANGELOG_FILE: "CHANGELOG.md" + + steps: + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Get version + id: get_version + run: | + RELEASE_VERSION=$(cat modular_api/version.py | awk -F"__version__ =" {'print $2'} | sed -e 's|["'\'' '^',]||g' | xargs) + echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV + echo "release_version=$RELEASE_VERSION" >> $GITHUB_OUTPUT + echo "Name ${{ github.ref_name }}. Version $RELEASE_VERSION" + + - name: Fetching previous version + id: get_previous_version + run: | + git fetch --tags + PREVIOUS_VERSION=$(git tag --sort=-creatordate | sed -n '2p' | sed 's/^v//') + echo "PREVIOUS_VERSION=$PREVIOUS_VERSION" >> $GITHUB_ENV + echo "previous_version=$PREVIOUS_VERSION" >> $GITHUB_OUTPUT + echo "Previous version: $PREVIOUS_VERSION" + + - name: Fetching release notes + id: release_notes + run: | + extract_release_notes() { + changelog_file=$1 + current_version=$2 + previous_version=$3 + + # Escape dots in version for regex + current_version_escaped=$(echo "$current_version" | sed 's/\./\\./g') + previous_version_escaped=$(echo "$previous_version" | sed 's/\./\\./g') + + # Extract release notes + release_notes=$(awk "/## \[$current_version_escaped\]/,/## \[$previous_version_escaped\]/" "$changelog_file" | sed '$d') + echo "$release_notes" + } + + RELEASE_NOTES=$(extract_release_notes ${{ env.CHANGELOG_FILE }} ${{ steps.get_version.outputs.release_version }} ${{ steps.get_previous_version.outputs.previous_version }}) + echo "Release notes:" + echo "$RELEASE_NOTES" + echo "$RELEASE_NOTES" > release_notes.md + + - name: Create tag + uses: actions/github-script@v7 + with: + script: | + github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: 'refs/tags/${{ steps.get_version.outputs.release_version }}', + sha: context.sha + }) + + - name: Create release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ steps.get_version.outputs.release_version }} + name: ${{ steps.get_version.outputs.release_version }} + body_path: release_notes.md + prerelease: false + draft: false + make_latest: true