Skip to content

Commit

Permalink
CI: open a PR on the celo-org/docs automagically (#110)
Browse files Browse the repository at this point in the history
* ci: first test

* ci: add trigger on push on this branch only

* fix: typo

* fix: commit ref

* fix: submodule fetching?

* fix: typo

* fix: sha?

* ci: token?

* ci: token?

* adding docs token from akeyless

* updating uses path

* adding the necessary server url

* ci: token?

* fix: repo

* fix: branches

* fix: token usage?

* fix: setup env differently

* fix: use checkout action

* fix: typo

* fix: fetch all branches

* fix: fetch differently

* fix: fetch

* fix: fetch?

* fix: fetch??

* fix: use ubuntu-latest in order to get gh

* ci: better PR body

* fix: only create a PR when CLI is released

* chore: use the script in the target repo

---------

Co-authored-by: pputman-clabs <patrick.putman@clabs.co>
  • Loading branch information
nicolasbrugneaux and pputman-clabs authored Feb 2, 2024
1 parent 0805fe4 commit 647050e
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 5 deletions.
92 changes: 92 additions & 0 deletions .github/workflows/open-docs-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
name: Open a pull-request on the celo-org/docs repository

on:
workflow_call:
inputs:
commit:
description: 'Commit of the developer-tooling repo that the submodule will be updated to'
type: string
required: true

workflow_dispatch:
inputs:
commit:
description: 'Commit of the developer-tooling repo that the submodule will be updated to'
type: string
required: true

jobs:
open-docs-pr:
name: Open a pull-request on the celo-org/docs repository
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
pull-requests: write
repository-projects: write
steps:
- name: Fetch secrets from AKeyless
id: fetch-secrets
uses: docker://us-west1-docker.pkg.dev/devopsre/akeyless-public/akeyless-action:latest
with:
access-id: p-kf9vjzruht6l
api-url: https://api.gateway.akeyless.celo-networks-dev.org
dynamic-secrets: '{"/dynamic-secrets/keys/github/docs/contents=write,pull_requests=write":"DOCS_TOKEN"}'

- name: Checkout Repo
uses: actions/checkout@v4
with:
repository: 'celo-org/docs'
submodules: 'recursive'
fetch-depth: 0
ref: main
token: ${{ env.DOCS_TOKEN }}

- name: Open pull-request
env:
COMMIT: ${{ inputs.commit }}
REPOSITORY: 'celo-org/docs'
DOCS_CWD: 'celo-docs'
BASE_BRANCH: main
NEW_BRANCH: 'ci/${{ github.run_id }}-${{ github.run_attempt }}'
BOT_NAME: 'github-actions'
BOT_EMAIL: 'github-actions@github.com'

run: |
set -x
# Setup the committers identity.
git config --global user.name $BOT_NAME
git config --global user.email $BOT_EMAIL
# Create a new feature branch for the changes.
git checkout -b $NEW_BRANCH
cd submodules/developer-tooling
git fetch --all
git checkout $COMMIT
cd ../..
./scripts/copy-generated-docs.sh
git status
git add submodules/developer-tooling
git add docs/cli
git commit -m "chore: update developer-tooling submodule"
git push origin $NEW_BRANCH
cat >/tmp/pr-body.md <<EOL
Update developer-tooling submodule to [$COMMIT](https://github.com/celo-org/developer-tooling/commit/$COMMIT).
Merging this pull-request will update the docs using generated files (such as the CLI docs).
🤖 _This pull-request was opened by a robot beep boop._ 🤖
EOL
echo "$DOCS_TOKEN" > token.txt
gh auth login --with-token < token.txt
gh pr create \
--body-file /tmp/pr-body.md \
--title "chore: update auto-generated docs reference from developer-tooling" \
--head "$NEW_BRANCH" \
--base "$BASE_BRANCH"
18 changes: 13 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ jobs:
id-token: write
pull-requests: write
repository-projects: write
outputs:
publishedPackages: ${{ steps.changesets.outputs.publishedPackages }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Akeyless Get Secrets
id: get_auth_token
uses:
docker://us-west1-docker.pkg.dev/devopsre/akeyless-public/akeyless-action:latest
uses: docker://us-west1-docker.pkg.dev/devopsre/akeyless-public/akeyless-action:latest
with:
api-url: https://api.gateway.akeyless.celo-networks-dev.org
access-id: p-kf9vjzruht6l
Expand All @@ -34,8 +35,8 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 18.x
- name: "enable corepack for yarn"
run : sudo corepack enable yarn
- name: 'enable corepack for yarn'
run: sudo corepack enable yarn
shell: bash
# must call twice because of chicken and egg problem with yarn and node
- uses: actions/setup-node@v4
Expand All @@ -54,4 +55,11 @@ jobs:
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: yarn release
version: yarn version-and-reinstall
version: yarn version-and-reinstall

open-docs-pr:
needs: release
if: ${{ contains(fromJson(needs.release.outputs.publishedPackages).*.name, '@celo/cli') }}
uses: celo-org/developer-tooling/.github/workflows/open-docs-pr.yml@main
with:
commit: ${{ github.sha }}

0 comments on commit 647050e

Please sign in to comment.