From 201b9b9673ac83ce0137b15f1c1bd58e94df06b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Fri, 22 Oct 2021 01:15:54 +0200 Subject: [PATCH] task: implement release action --- .github/contributing.md | 45 ++------- .github/workflows/{ci.yaml => cicd.yaml} | 6 +- .github/workflows/release.yaml | 122 +++++++++++++++++++++++ 3 files changed, 131 insertions(+), 42 deletions(-) rename .github/workflows/{ci.yaml => cicd.yaml} (93%) create mode 100644 .github/workflows/release.yaml diff --git a/.github/contributing.md b/.github/contributing.md index c1e3673ae1..0bcbe39e08 100644 --- a/.github/contributing.md +++ b/.github/contributing.md @@ -20,42 +20,9 @@ ## For Release - create releases following [semver policy](https://semver.org/) -- we are using [gren](https://github.com/github-tools/github-release-notes) to generate the changelog and releases - -### One Time Steps - -- Generate API Token as described in [gren's README.md](https://github.com/github-tools/github-release-notes) -- On Windows do `setx GREN_GITHUB_TOKEN ` and restart your shell - -### Steps per Release - -- close all issues of the milestone or push them back to an open milestone -- close the milestone -- Tag and push the repo - - ```shell - git tag --message "" - git push origin - ``` - -- regenerate changelog with _gren_ - - ```shell - npx github-release-notes@0.17.1 changelog --generate --override --tags=all - ``` - -- add the changelog to git and update the tag - - ```shell - git add exampleSite/content/basics/CHANGELOG.md - git commit --message "Ship tag " - git push origin main - git tag --message "" --force - git push --force origin - ``` - -- generate release with _gren_ - - ```shell - npx github-release-notes@0.17.1 release --tags - ``` +- we are using GitHub actions to create new releases +- a release is based on a milestone named like the release itself - just the version number, eg: 1.1.0 +- remember that there have to be at least one closed issue assigned to the milestone +- the release action only runs successfully if all assigned issues for this milestone are closed +- the milestone itself will be closed during execution of the action +- a once released milestone can not be released again diff --git a/.github/workflows/ci.yaml b/.github/workflows/cicd.yaml similarity index 93% rename from .github/workflows/ci.yaml rename to .github/workflows/cicd.yaml index 78babedfff..3f2c409825 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/cicd.yaml @@ -1,4 +1,4 @@ -name: Deploy GitHub Pages +name: CI/CD on: push: # Build on all pushes but only deploy for main branch @@ -7,10 +7,10 @@ on: jobs: ci: - name: Run CI + name: Run CI/CD runs-on: ubuntu-latest steps: - - name: Checkout site + - name: Checkout repo uses: actions/checkout@v2 with: submodules: true # Fetch Hugo themes (true OR recursive) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000000..72ffac74c3 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,122 @@ +name: Release + +on: + workflow_dispatch: + inputs: + milestone: + description: 'Milestone for this release' + required: true + +jobs: + release_state: + name: Get tag and milestone state + runs-on: ubuntu-latest + env: + MILESTONE: ${{ github.event.inputs.milestone }} # To avoid code injection + outputs: + has_closed_issues: ${{ fromJSON(steps.closed_issues.outputs.data).search.issueCount > 0 }} + has_open_issues: ${{ fromJSON(steps.open_issues.outputs.data).search.issueCount > 0 }} + has_unique_tag: ${{ steps.unique_tag.outcome == 'failure' }} + steps: + - name: Checkout repo + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Get closed issues for milestone + id: closed_issues + uses: octokit/graphql-action@v2.x + with: + query: | + query { + search(first: 1, type: ISSUE, query: "user:${{ github.repository_owner }} repo:${{ github.event.repository.name }} milestone:${{ env.MILESTONE }} state:closed") { + issueCount + } + } + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Get open issues for milestone + id: open_issues + uses: octokit/graphql-action@v2.x + with: + query: | + query { + search(first: 1, type: ISSUE, query: "user:${{ github.repository_owner }} repo:${{ github.event.repository.name }} milestone:${{ env.MILESTONE }} state:open") { + issueCount + } + } + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Get tag uniqueness + id: unique_tag + continue-on-error: true + run: git rev-parse "$MILESTONE" -- + + release_log: + name: Log tag and milestone state + needs: release_state + runs-on: ubuntu-latest + env: + MILESTONE: ${{ github.event.inputs.milestone }} # To avoid code injection + steps: + - run: "echo has unique tag : ${{ needs.release_state.outputs.has_unique_tag }}" + - run: "echo has closed issues: ${{ needs.release_state.outputs.has_closed_issues }}" + - run: "echo has open issues : ${{ needs.release_state.outputs.has_open_issues }}" + + release: + name: Create release + needs: release_state + if: needs.release_state.outputs.has_closed_issues == 'true' && needs.release_state.outputs.has_open_issues == 'false' && needs.release_state.outputs.has_unique_tag == 'true' + runs-on: ubuntu-latest + env: + MILESTONE: ${{ github.event.inputs.milestone }} # To avoid code injection + GREN_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Checkout repo + uses: actions/checkout@v2 + + - name: Setup node + uses: actions/setup-node@v2 + with: + node-version: '16' + + - name: Setup git env + run: | + git config user.name "GitHub Actions Bot" + git config user.email "<>" + + - name: Close milestone + uses: Akkjon/close-milestone@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + milestone_name: ${{ env.MILESTONE }} + + - name: Create provisionary tag + run: git tag --message "" "$MILESTONE" + + - name: Push provisionary tag + run: git push origin "$MILESTONE" + + - name: Update changelog + run: npx github-release-notes@0.17.1 changelog --generate --override --tags=all + + - name: Stage changelog + run: git add * + + - name: Commit changelog + run: git commit --message "Ship tag $MILESTONE" + + - name: Push changelog + run: git push origin main + + - name: Create final tag + run: git tag --force --message "" "$MILESTONE" + + - name: Push final tag + run: git push --force origin "$MILESTONE" + + - name: Publish release + run: npx github-release-notes@0.17.1 release --tags "$MILESTONE"