daily docs sync PR #834
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: daily docs sync PR | |
on: | |
schedule: | |
# Runs "at minute 44 past midnight" (see https://crontab.guru) | |
# Reason is avoiding full hour peak | |
- cron: "44 0 * * *" | |
env: | |
BOT_USERNAME: soldocsbot | |
BOT_EMAIL: solidity-docs-translations@ethereum.org | |
GITHUB_REPOSITORY_OWNER: solidity-docs | |
jobs: | |
collectTranslationRepositories: | |
runs-on: ubuntu-latest | |
outputs: | |
repos: ${{ steps.collect-repos.outputs.repos }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Collect all translation repositories | |
id: collect-repos | |
run: | | |
langs=() | |
# collect all existent language repositories and their respective codes | |
for lang_file in langs/*.json; do | |
name=$(jq --raw-output '.name' "$lang_file") | |
code=$(jq --raw-output '.code' "$lang_file") | |
# concatenate the code and the converted lowercase name | |
# to match the repositories names | |
langs+=("${code}-${name,,}") | |
done | |
# convert to json array | |
langs_json=$(printf '\"%s\",' "${langs[@]}") | |
# Remove the trailing comma | |
echo "repos=[${langs_json%,}]" >> $GITHUB_OUTPUT | |
createPullRequest: | |
runs-on: ubuntu-latest | |
needs: collectTranslationRepositories | |
strategy: | |
# In the context matrix strategy, fail-fast means, if one of the jobs | |
# fails,the rest of the jobs will be canceled. In our case, this can | |
# be a limitation. When merging or creating PR to one repository fails, | |
# the rest still can be good. | |
fail-fast: false | |
matrix: | |
# This means, that all pull requests will be processed simultaneously | |
# and independently of each other. | |
repos: ${{fromJson(needs.collectTranslationRepositories.outputs.repos)}} | |
steps: | |
- name: Fetch translation repository | |
uses: actions/checkout@v2 | |
with: | |
token: ${{ secrets.PAT }} | |
repository: ${{ env.GITHUB_REPOSITORY_OWNER }}/${{ matrix.repos }} | |
# By default, checkout is fetching only the last commit. This will | |
# cause "unrelated histories" error. "0" means unlimited fetch-depth. | |
fetch-depth: 0 | |
# This is the working copy we'll prepare the sync PR in. | |
path: translation/ | |
- name: Configure translation repository | |
run: | | |
cd translation/ | |
git config user.name "$BOT_USERNAME" | |
git config user.email "$BOT_EMAIL" | |
git remote add english "https://github.com/ethereum/solidity.git" | |
git fetch english develop | |
- name: Fetch main Solidity repository | |
uses: actions/checkout@v2 | |
with: | |
repository: ethereum/solidity | |
fetch-depth: 0 | |
# This is the checkout where we can safely fetch the tags from the main Soldity repo and use git describe. | |
# Translation repositories have their own version tags that conflict with the ones in the main repo. | |
path: solidity/ | |
- name: Fetch bot's repository | |
uses: actions/checkout@v2 | |
with: | |
token: ${{ secrets.PAT }} | |
repository: ${{ github.repository }} | |
path: bot/ | |
- name: Load bot configuration from translation-bot.json in the translation repository | |
id: bot-config | |
run: | | |
bot/scripts/load-translation-bot-config.sh translation/translation-bot.json | |
- name: Prepare pull request title and description | |
if: ${{ steps.bot-config.outputs.bot_disabled == 'false' }} | |
run: | | |
# Use the main repository checkout with tags to get them in `git describe` output. | |
cd solidity/ | |
../bot/scripts/generate-pr-body.sh | |
- name: Check if sync branch already exists | |
id: check-sync-branch | |
if: ${{ steps.bot-config.outputs.bot_disabled == 'false' }} | |
run: | | |
pushd solidity/ | |
sync_branch="sync-$(git describe --tags --always develop)" | |
echo "branch_name=$sync_branch" >> "$GITHUB_OUTPUT" | |
popd | |
cd translation/ | |
../bot/scripts/check-remote-branch.sh "$sync_branch" | |
- name: Prepare pull request content | |
if: ${{ steps.bot-config.outputs.bot_disabled == 'false' && steps.check-sync-branch.outputs.branch_exists == 'false' }} | |
run: | | |
cd translation/ | |
# NOTE: The script will end up not creating a merge commit if there are no new upstream changes. | |
# In that case we expect that the PR action will simply not create a PR. | |
../bot/scripts/pull-and-resolve-english-changes.sh english/develop "$pr_title" | |
if [[ ${{ steps.bot-config.outputs.randomly_assign_maintainers }} == 'true' ]]; then | |
../bot/scripts/set-assignees.sh "${{ matrix.repos }}" | |
fi | |
- name: Remove this repository | |
if: ${{ steps.bot-config.outputs.bot_disabled == 'false' && steps.check-sync-branch.outputs.branch_exists == 'false' }} | |
run: | | |
rm -rf bot/ | |
- name: Create Pull Request | |
if: ${{ steps.bot-config.outputs.bot_disabled == 'false' && steps.check-sync-branch.outputs.branch_exists == 'false' }} | |
uses: peter-evans/create-pull-request@v3 | |
with: | |
path: translation/ | |
token: "${{ secrets.PAT }}" | |
commit-message: "${{ env.pr_title }}" | |
committer: "${{ env.BOT_USERNAME }} <${{ env.BOT_EMAIL }}>" | |
author: "${{ env.BOT_USERNAME }} <${{ env.BOT_EMAIL }}>" | |
branch: "${{ steps.check-sync-branch.outputs.branch_name }}" | |
title: "${{ env.pr_title }}" | |
body: "${{ env.pr_body }}" | |
labels: "${{ join(fromJSON(steps.bot-config.outputs.pr_labels)) }}" | |
assignees: ${{ env.assignee }} | |
reviewers: ${{ env.reviewer }} |