Added quadratic voting #252
Workflow file for this run
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: 01-Release-Tagging | |
on: | |
pull_request: | |
types: | |
- closed | |
env: | |
RELEASE_LABEL: release | |
RELEASE_LABEL_DRYRUN: release-dryrun | |
jobs: | |
test_bundle: | |
uses: ./.github/workflows/test-bundle.yml | |
prepare: | |
needs: [test_bundle] | |
runs-on: ubuntu-latest | |
if: github.event.pull_request.merged | |
outputs: | |
PR_LABELS_STR: ${{ steps.getinfo.outputs.pr_labels_str }} | |
PR_LABELS_TOTAL: ${{ steps.getinfo.outputs.pr_labels_total }} | |
PKG_VER_FINAL: ${{ steps.getinfo.outputs.pkg_ver_final }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
## Tag pattern: v1.2.3-xyz | |
- name: Get PR labels and pkg version | |
id: getinfo | |
run: | | |
PRLABELSLIST="${{ toJson(github.event.pull_request.labels.*.name) }}" | |
echo "Labels list: $PRLABELSLIST" | |
PRLABELSSTR=$(echo $PRLABELSLIST | sed 's/\[//g' | sed 's/\]//g' | sed 's/\s*//g' | tr -d '\n') | |
echo "Labels string: $PRLABELSSTR" | |
PRLABELSARRAY=($(echo $PRLABELSSTR | tr ',' '\n')) | |
PRLABELSTOTAL="${#PRLABELSARRAY[@]}" | |
echo "Total Labels: $PRLABELSTOTAL" | |
echo "pr_labels_str=$PRLABELSSTR" >> $GITHUB_OUTPUT | |
echo "pr_labels_total=$PRLABELSTOTAL" >> $GITHUB_OUTPUT | |
PKG_VER=$(cat package.json | jq -r .version) | |
PKGVERFINAL="" | |
if [ "$PRLABELSTOTAL" == "1" ]; then | |
case "$PRLABELSSTR" in | |
"${{ env.RELEASE_LABEL }}") | |
PKGVERFINAL="v${PKG_VER}";; ## nothing to append | |
"${{ env.RELEASE_LABEL_DRYRUN }}") | |
PKGVERFINAL="v${PKG_VER}-dryrun";; ## append to tag dryrun suffix | |
*) | |
echo "Error: The Pull Request has not the right labels." | |
echo "Error: The Pull Request has not the right labels." >> $GITHUB_STEP_SUMMARY | |
exit 1;; | |
esac | |
else | |
echo "Error: The Pull Request has $PRLABELSTOTAL and should have only 1 label." | |
echo "Error: The Pull Request has $PRLABELSTOTAL and should have only 1 label." >> $GITHUB_STEP_SUMMARY | |
exit 1 | |
fi | |
echo "Pkg Version final: $PKGVERFINAL" | |
echo "pkg_ver_final=$PKGVERFINAL" >> $GITHUB_OUTPUT | |
tagging: | |
name: Set Github Tag | |
runs-on: ubuntu-latest | |
needs: [prepare] | |
steps: | |
- name: Set Github Tag via API | |
id: settag | |
uses: actions/github-script@v6 | |
## This condition gets TRUE if used in this way: contains(toJson(xyz), 'substr') | |
if: ${{ contains( toJson(github.event.pull_request.labels.*.name), env.RELEASE_LABEL ) || contains( toJson(github.event.pull_request.labels.*.name), env.RELEASE_LABEL_DRYRUN ) }} | |
with: | |
github-token: ${{ secrets.VOCDONIBOT_PAT_TRIGGER_WORKFLOW }} | |
script: | | |
github.rest.git.createRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: `refs/tags/${{ needs.prepare.outputs.PKG_VER_FINAL }}`, | |
sha: "${{ github.sha }}" | |
}) | |
- name: Confirm Tag creation | |
if: always() | |
run: | | |
if [[ "${{ steps.settag.outcome }}" != 'success' ]]; then | |
echo "Error: The Tag ${{ needs.prepare.outputs.PKG_VER_FINAL }} cannot be created because It already exists." >> $GITHUB_STEP_SUMMARY | |
else | |
echo "The Tag ${{ needs.prepare.outputs.PKG_VER_FINAL }} has been created successfully." >> $GITHUB_STEP_SUMMARY | |
fi |