Generate docs for new version #80
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: Generate docs for new version | |
on: | |
workflow_dispatch: | |
inputs: | |
tag: | |
description: Helmwave tag to generate docs for | |
required: true | |
type: string | |
permissions: | |
actions: write # to trigger workflow_dispatch | |
contents: write | |
pull-requests: write | |
jobs: | |
generate-new-docs: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Parse tag into docs version | |
id: parse-version | |
run: | | |
VERSION=$(echo "$TAG" | sed 's#^v\?\(.*\)\.\(.*\)\..*$#\1.\2.x#g') | |
echo "VERSION=${VERSION}" >> $GITHUB_ENV | |
env: | |
TAG: ${{ inputs.tag }} | |
- name: Find existing branch for version | |
id: find-branch | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ github.token }} | |
script: | | |
github.rest.git.getRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: "heads/" + process.env.VERSION, | |
}) | |
continue-on-error: true | |
- name: Create branch and PR for new version | |
id: create-version | |
uses: actions/github-script@v6 | |
if: ${{ steps.find-branch.outcome == 'failure' }} | |
with: | |
github-token: ${{ github.token }} | |
script: | | |
const mainBranch = github.rest.git.getRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: "heads/main", | |
}) | |
const lastMainCommit = github.rest.git.getCommit({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
commit_sha: (await mainBranch).data.object.sha, | |
}) | |
const newCommit = github.rest.git.createCommit({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
message: "chore: empty commit for " + process.env.VERSION + " version", | |
tree: (await lastMainCommit).data.tree.sha, | |
parents: [(await lastMainCommit).data.sha], | |
}) | |
await github.rest.git.createRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: "refs/heads/" + process.env.VERSION, | |
sha: (await newCommit).data.sha, | |
}) | |
await github.rest.pulls.create({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
head: process.env.VERSION, | |
base: "main", | |
title: "Generate docs for " + process.env.VERSION + " version" | |
}) | |
- name: Trigger publish branch workflow | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ github.token }} | |
script: | | |
await github.rest.actions.createWorkflowDispatch({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
workflow_id: "publish-b.yml", | |
ref: process.env.VERSION, | |
inputs: { | |
update_aliases: process.env.NEW_VERSION, | |
}, | |
}) | |
env: | |
NEW_VERSION: ${{ steps.find-branch.outcome == 'failure' }} |