Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Create LTS Versions #27

Create LTS Versions

Create LTS Versions #27

Workflow file for this run

name: Create LTS Versions
on:
schedule:
- cron: "0 0 1,16 * *"
workflow_dispatch:
jobs:
lts_needed:
name: Check for Diff Between Main and the Last LTS Version
runs-on: ubuntu-latest
outputs:
no_release: ${{ steps.get_releases.outputs.no_release }}
new_lts_zip: ${{ steps.get_releases.outputs.new_lts_zip }}
release_name: ${{ steps.get_releases.outputs.release_name }}
steps:
- name: Get Releases
id: get_releases
run: |
LTS_TIME=$(jq -r 'first(.[] | select(.name | match(".+LTS")) | .published_at)' <<< $(curl -Ls -H "Accept: application/vnd.github+json" -H "Authorization: token $TOKEN" $GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases)) # Get latest LTS version release time
read REL_TIME REL_ID REL_NAME REL_ZIP < <(echo $(curl -Ls -H "Accept: application/vnd.github+json" -H "Authorization: token $TOKEN" $GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases/latest | jq -r '.published_at, .id, .name, .zipball_url')) # Get info about latest release
if [ $REL_TIME '>' $LTS_TIME ]; then curl -s -X PATCH -H "Accept: application/vnd.github+json" -H "Authorization: token $TOKEN" $GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases/$REL_ID -d '{"name":"'"${REL_NAME}-LTS"'"}' > /dev/null; echo "new_lts_zip=$REL_ZIP" >> $GITHUB_OUTPUT; echo "release_name=$REL_NAME" >> $GITHUB_OUTPUT; else echo "no_release=true" >> $GITHUB_OUTPUT; fi # If there has been a non-LTS release since the last LTS release, create a new LTS release
env:
TOKEN: ${{ secrets.DX_GITHUB_TOKEN }}
create_lts:
name: Create A New LTS Release
runs-on: ubuntu-latest
needs: lts_needed
if: ${{!needs.lts_needed.outputs.no_release}}
steps:
- name: Download, Extract, and Build Site from Release
run: |
mkdir lts; curl -Lfs -H "Accept: application/vnd.github+json" -H "Authorization: token $TOKEN" $LTS_ZIP --output lts.zip; unzip -q lts.zip -d lts # Get and Unzip Release Archive
cd $(find ./ -type d -name "site"); mv ./* ../../; cd ../../ # Move contents of site directory to root of unzipped folder
tmpfile=$(mktemp); cp custom.config.json $tmpfile; jq "(.[] | select(.)) |= gsub(\"main\"; \"$REL_NAME\")" $tmpfile > custom.config.json; rm -f -- "$tmpfile" # Update Config for Spec Download Links
yarn install --pure-lockfile; yarn build # Install Packages and Build Static Site
env:
TOKEN: ${{ secrets.DX_GITHUB_TOKEN }}
LTS_ZIP: ${{ needs.lts_needed.outputs.new_lts_zip }}
REL_NAME: ${{ needs.lts_needed.outputs.release_name }}
GOOGLE_ANALYTICS_TRACKING_ID: "12345"
GTAG_TRACKING_ID: "12345"
- name: Update Bucket Name
id: bucket_name
run: |
BUCKET_NAME=$(echo "bandwidth-api-docs-${BUCKET_NAME}" | tr '[:upper:]' '[:lower:]' | sed -e "s/[^a-z0-9]/-/g") #convert to lowercase and convert non-alphanumerics with dashes
echo "bucket_name=$BUCKET_NAME" >> $GITHUB_OUTPUT
env:
BUCKET_NAME: ${{ needs.lts_needed.outputs.release_name }}
- name: Sync to S3
uses: Bandwidth/[email protected]
with:
bucket-name: ${{ steps.bucket_name.outputs.bucket_name }}
bucket-expiration: "180"
bucket-region: "us-east-1"
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
content-path: ./lts/build
update_lts_table:
name: Automatically update the LTS table
runs-on: ubuntu-latest
needs: [lts_needed, create_lts]
if: ${{!needs.lts_needed.outputs.no_release}}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Configure Git and Create Branch
run: |
git config user.email "[email protected]"
git config user.name "DX-Bandwidth"
git checkout -b auto-update-lts
- name: Get Latest LTS Releases and Update LTS Config File
run: |
cat > ./site/lts.config.json <<< $(jq -r '[nth(0,1,2,3,4,5,6,7,8,9,10,11;.[] | select(.name | match(".+LTS")) | .name | rtrimstr("-LTS"))] | unique | reverse' <<< $(curl -Ls -H "Accept: application/vnd.github+json" -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/Bandwidth/api-docs/releases?per_page=100))
env:
GITHUB_TOKEN: ${{ secrets.DX_GITHUB_TOKEN }}
- name: Commit Changes and Create Pull Request
run: |
git add site/lts.config.json
git commit -m 'update lts table'
git push origin auto-update-lts
gh pr create -B main -H auto-update-lts --title 'SWI-3486 Update LTS Versions Table' --body 'Auto-generated by Create LTS Versions Workflow'
env:
GITHUB_TOKEN: ${{ secrets.DX_GITHUB_TOKEN }}