Skip to content

Commit

Permalink
Simplify update README workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
superseb authored and manuelbuil committed Jan 10, 2024
1 parent 7383d9e commit 833fec5
Showing 1 changed file with 16 additions and 27 deletions.
43 changes: 16 additions & 27 deletions .github/workflows/update-readme.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Update README
on: workflow_dispatch
on:
workflow_dispatch:
release:
types: [published]

permissions:
contents: write
Expand All @@ -9,7 +12,7 @@ jobs:
update-readme:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Update README file
run: |
tagstmpfile=$(mktemp)
Expand Down Expand Up @@ -40,7 +43,7 @@ jobs:
id: branch
run: |
BRANCH="githubaction-update-readme-$(date +%Y-%m-%d-%H-%M-%S)"
echo "::set-output name=branch::$BRANCH"
echo "branch=${BRANCH}" >> $GITHUB_OUTPUT
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git checkout -b "$BRANCH"
Expand All @@ -51,28 +54,14 @@ jobs:
id: cpr
env:
SOURCE_BRANCH: ${{ steps.branch.outputs.branch }}
uses: actions/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let body = 'Auto-generated by GitHub Actions'
const { data: pr } = await github.rest.pulls.create({
title: `[${{ github.ref_name }}] update README with latest`,
body: body,
owner: context.repo.owner,
repo: context.repo.repo,
base: "${{ github.ref_name }}",
head: `${ process.env.SOURCE_BRANCH }`
});
await github.rest.issues.addLabels({
...context.repo,
issue_number: pr.number,
labels: ["status/auto-created"],
});
console.log('Created new pull request');
return pr.html_url;
- name: Check outputs
if: ${{ env.changes_exist == 'true' }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Pull Request URL - ${{ steps.cpr.outputs.result }}"
PR_TITLE="[${GITHUB_REF_NAME}] update README with latest"
PR_BODY="Auto-generated by GitHub Actions"
EXISTING_PR=$(gh pr list --limit 500 --json title,url | jq --arg title "${PR_TITLE}" -r '.[] | select(.title==$title) | .url')
CREATED_PR=$(gh pr create --title "${PR_TITLE}" --body "${PR_BODY}" --label "status/auto-created" --base "${GITHUB_REF_NAME}" --head "${SOURCE_BRANCH}")
echo "Created pull request: ${CREATED_PR}" >> $GITHUB_STEP_SUMMARY
if [ -n "${EXISTING_PR}" ]; then
gh pr close --comment "Superseded by ${CREATED_PR}" --delete-branch "${EXISTING_PR}"
echo "Closed previous pull request: ${EXISTING_PR}" >> $GITHUB_STEP_SUMMARY
fi

0 comments on commit 833fec5

Please sign in to comment.