This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
Refresh embedded data.json files #52
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: Refresh embedded data.json files | |
on: workflow_dispatch | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
refresh-embedded-data: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repository code | |
uses: actions/checkout@v2 | |
- name: Run script to get data.json | |
id: run_script | |
run: | | |
bash scripts/get-embedded-data.sh > get-embedded-data.output | |
output="$(cat get-embedded-data.output)" | |
output="${output//$'\n'/\\n}" | |
output="${output// / }" # replace regular space with 'En Space' | |
echo "::set-output name=embedded-data::$output" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Check for repository changes | |
run: | | |
git add embedded/ | |
if git diff --cached --name-only --diff-filter=A --quiet --exit-code; then | |
echo "No changes found in repository" | |
echo "changes_exist=false" >> $GITHUB_ENV | |
else | |
echo "Changes found in repository" | |
git diff --name-only | |
echo "changes_exist=true" >> $GITHUB_ENV | |
fi | |
- name: Create branch, commit and push | |
if: ${{ env.changes_exist == 'true' }} | |
id: branch | |
run: | | |
BRANCH="githubaction-embedded-$(date +%Y-%m-%d-%H-%M-%S)" | |
echo "::set-output name=branch::$BRANCH" | |
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" | |
git commit -a -m 'add embedded versions' | |
git push origin "$BRANCH" | |
- name: Create Pull Request | |
if: ${{ env.changes_exist == 'true' }} | |
id: cpr | |
uses: actions/[email protected] | |
env: | |
SOURCE_BRANCH: ${{ steps.branch.outputs.branch }} | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const output = '${{ steps.run_script.outputs.embedded-data}}' | |
const { data: pr } = await github.rest.pulls.create({ | |
title: "[${{ github.ref_name }}] add new embedded versions", | |
body: `Auto-generated by GitHub Actions\n${output}`, | |
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: ["auto-created"], | |
}); | |
console.log('Created new pull request'); | |
return pr.html_url; | |
- name: Check outputs | |
if: ${{ env.changes_exist == 'true' }} | |
run: | | |
echo "Pull Request URL - ${{ steps.cpr.outputs.result }}" |