diff --git a/.changeset/arpit-bruno-patch-1-test.md b/.changeset/arpit-bruno-patch-1-test.md new file mode 100644 index 00000000..a7f06dc9 --- /dev/null +++ b/.changeset/arpit-bruno-patch-1-test.md @@ -0,0 +1,5 @@ +--- +"@opencollection/docs": minor +--- + +test: changeset label action (#1) diff --git a/.github/workflows/changeset.yml b/.github/workflows/changeset.yml new file mode 100644 index 00000000..d10e31f5 --- /dev/null +++ b/.github/workflows/changeset.yml @@ -0,0 +1,52 @@ +name: Changeset + +on: + pull_request: + types: [labeled] + +jobs: + changeset: + if: startsWith(github.event.label.name, 'changeset:') + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + + - name: Write the changeset + env: + LABEL: ${{ github.event.label.name }} + TITLE: ${{ github.event.pull_request.title }} + BRANCH: ${{ github.event.pull_request.head.ref }} + NUMBER: ${{ github.event.pull_request.number }} + run: | + bump="${LABEL#changeset:}" + slug=$(printf '%s' "$BRANCH" \ + | tr '[:upper:]' '[:lower:]' \ + | sed -e 's#[^a-z0-9]#-#g' -e 's#--*#-#g' -e 's#^-##' -e 's#-$##') + + mkdir -p .changeset + printf -- '---\n"@opencollection/docs": %s\n---\n\n%s (#%s)\n' \ + "$bump" "$TITLE" "$NUMBER" > ".changeset/${slug}.md" + + cat ".changeset/${slug}.md" + + - name: Commit it to the PR branch + env: + ACTOR: ${{ github.actor }} + ACTOR_ID: ${{ github.actor_id }} + run: | + git config user.name "$ACTOR" + git config user.email "${ACTOR_ID}+${ACTOR}@users.noreply.github.com" + git add .changeset + if git diff --cached --quiet; then + echo "changeset unchanged, nothing to commit" + exit 0 + fi + git commit -m "chore: add changeset" + git push +