From d55b1d5fcef18f2b0467c97de22bf2d05bf76bb1 Mon Sep 17 00:00:00 2001 From: Jorge Martin Espinosa Date: Tue, 20 Jun 2023 14:31:52 +0200 Subject: [PATCH] Try using ElementBot for recording screenshots too (#641) --- .github/workflows/recordScreenshots.yml | 4 +- .../workflows/scripts/recordScreenshots.sh | 42 ++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/.github/workflows/recordScreenshots.yml b/.github/workflows/recordScreenshots.yml index c28f4df26b..1790bb2a8d 100644 --- a/.github/workflows/recordScreenshots.yml +++ b/.github/workflows/recordScreenshots.yml @@ -16,6 +16,7 @@ jobs: - name: ⏬ Checkout with LFS uses: actions/checkout@v3 with: + persist-credentials: false lfs: 'true' - name: ☕️ Use JDK 17 uses: actions/setup-java@v3 @@ -30,5 +31,6 @@ jobs: - name: Record screenshots run: "./.github/workflows/scripts/recordScreenshots.sh" env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.DANGER_GITHUB_API_TOKEN }} GITHUB_REPOSITORY: ${{ secrets.GITHUB_REPOSITORY }} + diff --git a/.github/workflows/scripts/recordScreenshots.sh b/.github/workflows/scripts/recordScreenshots.sh index 8400d86913..2cfec13818 100755 --- a/.github/workflows/scripts/recordScreenshots.sh +++ b/.github/workflows/scripts/recordScreenshots.sh @@ -16,13 +16,43 @@ # limitations under the License. # -if [[ -z ${GITHUB_TOKEN} ]]; then - echo "Missing GITHUB_TOKEN variable" +TOKEN=$GITHUB_TOKEN +REPO=$GITHUB_REPOSITORY + +SHORT=t:,r: +LONG=token:,repo: +OPTS=$(getopt -a -n recordScreenshots --options $SHORT --longoptions $LONG -- "$@") + +eval set -- "$OPTS" +while : +do + case "$1" in + -t | --token ) + TOKEN="$2" + shift 2 + ;; + -r | --repo ) + REPO="$2" + shift 2 + ;; + --) + shift; + break + ;; + *) + echo "Unexpected option: $1" + help + ;; + esac +done + +if [[ -z ${TOKEN} ]]; then + echo "No token specified, either set the env var GITHUB_TOKEN or use the --token option" exit 1 fi -if [[ -z ${GITHUB_REPOSITORY} ]]; then - echo "Missing GITHUB_REPOSITORY variable" +if [[ -z ${REPO} ]]; then + echo "No repo specified, either set the env var GITHUB_REPOSITORY or use the --repo option" exit 1 fi @@ -35,6 +65,8 @@ git config user.email "benoitm+elementbot@element.io" git add -A git commit -m "Update screenshots" +BRANCH=$(git rev-parse --abbrev-ref HEAD) + echo "Pushing changes" -git push "https://$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY.git" +git push "https://$TOKEN@github.com/$REPO.git" $BRANCH:refs/heads/$BRANCH echo "Done!"