Merge pull request #171 from wp-graphql/test #4
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: "Create Changeset and Add Release Label" | ||
on: | ||
pull_request_target: | ||
types: | ||
- opened | ||
- edited | ||
- synchronize | ||
jobs: | ||
changeset: | ||
name: Create Changeset and Add Release Label | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
- name: Determine Release Type | ||
id: determine-release | ||
run: | | ||
PR_NUMBER=$(jq -r .number "$GITHUB_EVENT_PATH") | ||
RELEASE_TYPE="patch" | ||
LABELS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
"https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/labels" | jq -r '.[].name') | ||
echo "Labels on PR: $LABELS" | ||
for LABEL in $LABELS; do | ||
if [ "$LABEL" == "Release Type: Major" ]; then | ||
RELEASE_TYPE="major" | ||
break | ||
elif [ "$LABEL" == "Release Type: Minor" ]; then | ||
RELEASE_TYPE="minor" | ||
fi | ||
done | ||
echo "release_type=$RELEASE_TYPE" >> $GITHUB_ENV | ||
echo "changeset_type=$RELEASE_TYPE" >> $GITHUB_ENV | ||
- name: Debug Release Type | ||
run: echo "Determined release type: ${{ env.release_type }}" | ||
- name: Create Changeset | ||
run: | | ||
PR_TITLE=$(jq -r .title "$GITHUB_EVENT_PATH") | ||
TYPE=${{ env.changeset_type }} | ||
WORDS=("mushroom" "pepperoni" "pineapple" "bacon" "cheese" "olives" "peppers" "sausage" "onions" "spinach" "tomato" "ham" "chicken" "beef" "jalapeno" "broccoli" "anchovies" "artichoke" "garlic" "basil") | ||
COOK_TIMES=("10min" "12min" "15min" "18min" "20min") | ||
TEMPERATURES=("350F" "375F" "400F" "425F") | ||
RANDOM_WORD1=${WORDS[$RANDOM % ${#WORDS[@]}]} | ||
RANDOM_WORD2=${WORDS[$RANDOM % ${#WORDS[@]}]} | ||
RANDOM_TIME=${COOK_TIMES[$RANDOM % ${#COOK_TIMES[@]}]} | ||
RANDOM_TEMP=${TEMPERATURES[$RANDOM % ${#TEMPERATURES[@]}]} | ||
TIMESTAMP=$(date +%s) | ||
FILENAME="${RANDOM_WORD1}-${RANDOM_WORD2}-${RANDOM_TIME}-${RANDOM_TEMP}-${TIMESTAMP}.md" | ||
mkdir -p .changeset | ||
echo "---" > .changeset/$FILENAME | ||
echo "$TYPE: $TYPE" >> .changeset/$FILENAME | ||
echo "---" >> .changeset/$FILENAME | ||
echo "" >> .changeset/$FILENAME | ||
echo "$PR_TITLE" >> .changeset/$FILENAME | ||
echo "" >> .changeset/$FILENAME | ||
echo "_This changeset was automatically generated._" >> .changeset/$FILENAME | ||
- name: Configure Git | ||
run: | | ||
git config --global user.name 'github-actions[bot]' | ||
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | ||
- name: Commit Changeset | ||
run: | | ||
git add .changeset/$FILENAME | ||
git commit -m "chore: add changeset for $PR_TITLE" | ||
- name: Push Changes | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
git push origin HEAD:${{ github.head_ref }} | ||
- name: Add Release Label | ||
uses: actions/github-script@v4 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
github.issues.addLabels({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: context.issue.number, | ||
labels: [ "${{ env.release_type }}" ] | ||
}) |