update #110
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: Update to latest release | |
on: | |
repository_dispatch: | |
types: [update] | |
env: | |
VERSION_REGEX: '^[0-9]+\.[0-9]{4}\.[0-9]+$' | |
jobs: | |
latest: | |
name: Get latest PlaceOS version | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.version.outputs.version }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
repository: PlaceOS/PlaceOS | |
- name: Get latest version from PlaceOS/PlaceOS | |
id: version | |
run: | | |
latest=$(git tag --list | grep --extended-regexp '${{ env.VERSION_REGEX }}' | sort | tail -1) | |
echo ::set-output name=version::$latest | |
update: | |
if: needs.latest.outputs.version != 'nightly' | |
name: Update | |
needs: latest | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.GH_UPDATE_TOKEN }} | |
- name: Should Update? | |
id: should | |
run: | | |
if [[ $(git tag --list) =~ "placeos-${{ needs.latest.outputs.version }}"]]; then | |
# Ignore update if tag already exists | |
echo "::set-output name=update::false" | |
else | |
echo "::set-output name=update::true" | |
fi | |
- name: Update files | |
if: steps.should.outputs.update == 'true' | |
id: update | |
shell: bash | |
run: | | |
set -euo pipefail | |
set -x | |
branch=release/${{ needs.latest.outputs.version }} | |
echo ::set-output name=branch::$branch | |
# Update `.env` | |
sed --in-place=.bak -E 's/^PLACEOS_TAG=.*/PLACEOS_TAG=placeos-${{ needs.latest.outputs.version }}/g' \ | |
.env | |
# Update CI matrix | |
sed --in-place=.bak -E 's/^([ ]{10}- )(latest)/\1placeos-${{ needs.latest.outputs.version }}\n\1\2/g' \ | |
.github/workflows/ci.yml | |
- name: Commit and Push | |
if: steps.should.outputs.update == 'true' | |
shell: bash | |
env: | |
BRANCH: ${{ steps.update.outputs.branch }} | |
VERSION: ${{ needs.latest.outputs.version }} | |
run: | | |
set -euo pipefail | |
set -x | |
git config user.email "[email protected]" | |
git config user.name "PlaceOS Robot" | |
git checkout -b "${BRANCH}" | |
git add .env .github/workflows/ci.yml | |
git commit --message="build: update to ${VERSION}" | |
git push -u origin "${BRANCH}" | |
- name: Create PR | |
if: steps.should.outputs.update == 'true' | |
shell: bash | |
env: | |
BRANCH: ${{ steps.update.outputs.branch }} | |
VERSION: ${{ needs.latest.outputs.version }} | |
run: | | |
# Login with GitHub CLI | |
echo ${{ secrets.GH_UPDATE_TOKEN }} | gh auth login --with-token | |
# Create PR | |
gh pr create \ | |
--fill \ | |
--head "${BRANCH}" \ | |
--assignee 'placeos-robot' \ | |
--label 'type: maintenance' \ | |
--base master \ | |
--body "See the details for \`placeos-${VERSION}\`[here](https://github.com/PlaceOS/PlaceOS/releases/tag/${VERSION})." |