Create Release #32
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: Create Release | |
on: | |
workflow_dispatch: | |
inputs: | |
draft: | |
type: choice | |
description: "Create the release as draft" | |
options: | |
- "yes" | |
- "no" | |
default: "no" | |
required: true | |
force: | |
type: choice | |
description: "Force the creation of a release (even if no PR are found)" | |
options: | |
- "yes" | |
- "no" | |
default: "no" | |
required: true | |
jobs: | |
release: | |
runs-on: ubuntu-22.04 | |
permissions: | |
contents: write | |
packages: write | |
pull-requests: write | |
outputs: | |
tag: ${{ steps.output.outputs.tag }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # we need this because fetch-tags=true and because of a GHA bug: https://github.com/actions/checkout/issues/1471 | |
fetch-tags: true | |
- uses: actions/setup-go@v4 | |
with: | |
go-version: "1.21" | |
- id: create-release | |
uses: fabien-marty/github-create-next-semantic-release-action@main | |
with: | |
github-token: ${{ github.token }} # Let's use the default value of the current workflow | |
repository: ${{ github.repository }} # Let's use the default value of the current workflow | |
repository-owner: ${{ github.repository_owner }} # Let's use the default value of the current workflow | |
release-force: ${{ github.event.inputs.force == 'yes' }} | |
release-draft: ${{ github.event.inputs.draft == 'yes' }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set output | |
id: output | |
run: | | |
echo "tag=${{ steps.create-release.outputs.new-tag}}" >>"$GITHUB_OUTPUT" | |
- name: "Build" | |
run: | | |
make build | |
- name: "Generate Changelog" | |
run: | | |
./cmd/github-generate-changelog/github-generate-changelog --branch main . >CHANGELOG.md | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create a Changelog PR | |
run: | | |
DIFF=$(git status --short) | |
if test "${DIFF}" = ""; then | |
echo "No changes to commit => exit here" | |
exit 0 | |
fi | |
BRANCH="automatic-changelog" | |
N=`git fetch origin "${BRANCH}" 2>/dev/null || echo "NOTFOUND"` | |
if test "${N}" = "NOTFOUND"; then | |
echo "Branch: ${BRANCH} does not exist, let's create a new branch..." | |
git checkout -b "${BRANCH}" | |
else | |
echo "Branch: ${BRANCH} already exists, let's reset this branch with ${GITHUB_REF}..." | |
git stash save --include-untracked | |
git checkout -b "${BRANCH}" "origin/${BRANCH}" | |
git reset --hard "${GITHUB_REF}" | |
git stash apply | |
fi | |
echo "Let's commit and push the changes..." | |
git config --global user.name 'Automatic Changelog' | |
git config --global user.email '[email protected]' | |
git add -A | |
git commit -m "Automatic Changelog" | |
git push -u origin -f "${BRANCH}" | |
echo "Checking existing PRs for head:${BRANCH}..." | |
N=`gh pr list --search "head:${BRANCH} is:pr is:open" --json number |grep number || true` | |
if test "${N}" != ""; then | |
echo "There is already an open PR for this branch => exit here" | |
exit 0 | |
fi | |
echo "Let's create the PR" | |
gh pr create --title "Automatic Changelog" --body "Automatic Changelog" --repo "${{ github.repository }}" --head "${BRANCH}" --label "Type: Hidden" | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
release_go_binary: | |
needs: release | |
name: Release Go Binary | |
runs-on: ubuntu-22.04 | |
if: ${{ github.event.inputs.draft == 'no' && needs.release.outputs.tag != '' }} | |
permissions: | |
contents: write | |
packages: write | |
pull-requests: read | |
strategy: | |
matrix: | |
goos: [linux, windows, darwin] | |
goarch: [amd64, arm64] | |
exclude: | |
- goarch: arm64 | |
goos: windows | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Debug | |
run: | | |
echo "tag=${{ needs.release.outputs.tag }}" | |
- uses: wangyoucao577/go-release-action@v1 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
goos: ${{ matrix.goos }} | |
goarch: ${{ matrix.goarch }} | |
project_path: ./cmd/github-create-next-semantic-release | |
binary_name: github-create-next-semantic-release | |
compress_assets: "OFF" | |
pre_command: export CGO_ENABLED=0 | |
release_tag: ${{ needs.release.outputs.tag }} | |
- uses: wangyoucao577/go-release-action@v1 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
goos: ${{ matrix.goos }} | |
goarch: ${{ matrix.goarch }} | |
project_path: ./cmd/github-next-semantic-version | |
binary_name: github-next-semantic-version | |
compress_assets: "OFF" | |
pre_command: export CGO_ENABLED=0 | |
release_tag: ${{ needs.release.outputs.tag }} | |
- uses: wangyoucao577/go-release-action@v1 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
goos: ${{ matrix.goos }} | |
goarch: ${{ matrix.goarch }} | |
project_path: ./cmd/github-generate-changelog | |
binary_name: github-generate-changelog | |
compress_assets: "OFF" | |
pre_command: export CGO_ENABLED=0 | |
release_tag: ${{ needs.release.outputs.tag }} |