From 3a27f53db58d73be5afbb47f2149fc4a72265bfa Mon Sep 17 00:00:00 2001 From: Jens Reimann Date: Fri, 19 Apr 2024 08:50:46 +0200 Subject: [PATCH] ci: add a release workflow, just the release and release notes --- .github/workflows/release.yaml | 78 ++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..6c42472 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,78 @@ +name: release + +on: + push: + # Releases are tags named 'v', and must have the "major.minor.micro", for example: "0.1.0". + # Release candidates are tagged as `v-rc`, for example: "0.1.0-rc1". + tags: + - "v*" + +permissions: + contents: write # for creating a release + +jobs: + + init: + runs-on: ubuntu-22.04 + outputs: + version: ${{steps.version.outputs.version}} + prerelease: ${{steps.state.outputs.prerelease}} + steps: + - name: Evaluate state + id: state + env: + HEAD_REF: ${{github.head_ref}} + run: | + test -z "${HEAD_REF}" && (echo 'do-publish=true' >> $GITHUB_OUTPUT) + if [[ "${{ github.event.ref }}" =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo release=true >> $GITHUB_OUTPUT + elif [[ "${{ github.event.ref }}" =~ ^refs/tags/v.*$ ]]; then + echo prerelease=true >> $GITHUB_OUTPUT + fi + - name: Set version + id: version + run: | + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + [ "$VERSION" == "main" ] && VERSION=latest + echo "Version: $VERSION" + echo "version=$VERSION" >> $GITHUB_OUTPUT + + + # check that our CI would pass + ci: + uses: ./.github/workflows/ci.yaml + + # publish directly after CI check + publish: + needs: [ init, ci ] + runs-on: ubuntu-22.04 + steps: + + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install convco + run: | + curl -sLO https://github.com/convco/convco/releases/download/v0.5.1/convco-ubuntu.zip + unzip convco-ubuntu.zip + sudo install convco /usr/local/bin + + - name: Generate changelog + run: | + convco changelog -s --max-majors=1 --max-minors=1 --max-patches=1 -n > /tmp/changelog.md + + - name: Create Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TAG: v${{ needs.init.outputs.version }} + run: | + OPTS="" + + if [[ "${{ needs.init.outputs.prerelease }}" == "true" ]]; then + OPTS="${OPTS} -p" + fi + + gh release create ${OPTS} --title "${{ needs.init.outputs.version }}" -F /tmp/changelog.md ${TAG}