Skip to content

Commit

Permalink
chore(frontend): fix bash trap, improve disabling the protection and …
Browse files Browse the repository at this point in the history
…reorganize scripts (#94)
  • Loading branch information
Lodin authored Sep 7, 2021
1 parent aa5a1d1 commit cd6c1f6
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/frontend-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
env:
CI: true
- name: Bump New Version
run: sh scripts/bump.sh
run: sh scripts/bump/exec.sh
env:
GIT_RELEASE_TOKEN: ${{ secrets.GIT_RELEASE_TOKEN }}
REPO: ${{ github.repository }}
Expand Down
10 changes: 10 additions & 0 deletions frontend/scripts/bump/disabled-protection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"required_status_checks": null,
"enforce_admins": false,
"required_pull_request_reviews": null,
"restrictions": null,
"required_linear_history": false,
"allow_force_pushes": null,
"allow_deletions": false,
"required_conversation_resolution": false
}
File renamed without changes.
18 changes: 9 additions & 9 deletions frontend/scripts/bump.sh → frontend/scripts/bump/exec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
# Fails the script if any command failed or any variable is unset
set -eu

branch=main
branch=test/workflow-test
dir=$(dirname -- "$0")

# shellcheck disable=SC2139
alias ghr="curl https://api.github.com/repos/$REPO/branches/$branch/protection \
-H 'Accept: application/vnd.github.v3+json' \
-H 'Authorization: token $GIT_RELEASE_TOKEN' \
-s"

node scripts/update-package-versions.js "$VERSION_TAG"
node "$dir"/update-package-versions.js "$VERSION_TAG"

git add --all

Expand All @@ -22,19 +23,18 @@ git \

protection_config=$(ghr -X GET)

remapped=$(node scripts/protection-remap.js "$protection_config")
remapped=$(node "$dir"/protection-remap.js "$protection_config")

# Restores the protection of the branch
restore_protection() {
ghr -X PUT -d "$remapped" > /dev/null
echo "Branch protection restored"
echo "[$(date -Iseconds)][info] Protection of ${branch} branch restored"
}

# Will execute "restore" function if "git push" causes an error
trap "restore" ERR
# Will execute "restore_protection" function in the end of the script even if
# the script exits with an error
trap "restore_protection" EXIT

ghr -X DELETE > /dev/null
< "$dir"/disabled-protection.json ghr -X PUT -d '@-' > /dev/null

git push https://vaadin-bot:"$GIT_RELEASE_TOKEN"@github.com/"$REPO".git HEAD:$branch

restore_protection
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const {
input: [version],
} = meow({ importMeta: import.meta });

const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const root = resolve(dirname(fileURLToPath(import.meta.url)), '../..');

async function updateLernaConfig() {
const lernaConfigFile = resolve(root, 'lerna.json');
Expand Down

0 comments on commit cd6c1f6

Please sign in to comment.