|
| 1 | +name: Create LTS Versions |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 0 1,16 * *' |
| 6 | + |
| 7 | +jobs: |
| 8 | + lts_needed: |
| 9 | + name: Check for Diff Between Main and the Last LTS Version |
| 10 | + runs-on: ubuntu-latest |
| 11 | + outputs: |
| 12 | + no_release: ${{ steps.get_releases.outputs.no_release }} |
| 13 | + new_lts_zip: ${{ steps.get_releases.outputs.new_lts_zip }} |
| 14 | + release_name: ${{ steps.get_releases.outputs.release_name }} |
| 15 | + steps: |
| 16 | + - name: Get Releases |
| 17 | + id: get_releases |
| 18 | + run: | |
| 19 | + 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 |
| 20 | + 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 |
| 21 | + 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 "::set-output name=new_lts_zip::$REL_ZIP"; echo "::set-output name=release_name::$REL_NAME"; else echo "::set-output name=no_release::true"; fi # If there has been a non-LTS release since the last LTS release, create a new LTS release |
| 22 | + env: |
| 23 | + TOKEN: ${{ secrets.DX_GITHUB_TOKEN }} |
| 24 | + |
| 25 | + create_lts: |
| 26 | + name: Create A New LTS Release |
| 27 | + runs-on: ubuntu-latest |
| 28 | + needs: lts_needed |
| 29 | + if: ${{!needs.lts_needed.outputs.no_release}} |
| 30 | + steps: |
| 31 | + - name: Download, Extract, and Build Site from Release |
| 32 | + run: | |
| 33 | + 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 |
| 34 | + cd $(find ./ -type d -name "site"); mv ./* ../../; cd ../../; yarn install --pure-lockfile; yarn build # Build Static Site |
| 35 | + env: |
| 36 | + TOKEN: ${{ secrets.DX_GITHUB_TOKEN }} |
| 37 | + LTS_ZIP: ${{ needs.lts_needed.outputs.new_lts_zip }} |
| 38 | + REL_NAME: ${{ needs.lts_needed.outputs.release_name }} |
| 39 | + |
| 40 | + - name: Update Bucket Name |
| 41 | + id: bucket_name |
| 42 | + run: | |
| 43 | + 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 |
| 44 | + echo "::set-output name=bucket_name::$BUCKET_NAME" |
| 45 | + env: |
| 46 | + BUCKET_NAME: ${{ needs.lts_needed.outputs.release_name }} |
| 47 | + |
| 48 | + - name: Sync to S3 |
| 49 | + |
| 50 | + with: |
| 51 | + bucket-name: ${{ steps.bucket_name.outputs.bucket_name }} |
| 52 | + bucket-expiration: '180' |
| 53 | + bucket-region: 'us-east-1' |
| 54 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 55 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 56 | + content-path: ./lts/build |
0 commit comments