Check for new releases #24
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: Check for new releases | |
on: | |
schedule: | |
- cron: '0 0 * * *' | |
workflow_dispatch: | |
jobs: | |
check-release: | |
runs-on: ubuntu-latest | |
env: | |
TARGET_REPO: "PathOfBuildingCommunity/PathOfBuilding" | |
VERSION_FILE: "version.json" | |
steps: | |
- uses: actions/create-github-app-token@v1 | |
id: app-token | |
with: | |
app-id: ${{ secrets.TOKEN_APP_ID }} | |
private-key: ${{ secrets.TOKEN_PRIVATE_KEY }} | |
- uses: actions/checkout@v4 | |
with: | |
token: ${{ steps.app-token.outputs.token }} | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: '22.5.1' | |
cache: npm | |
- name: Get latest releases | |
id: get_releases | |
uses: actions/github-script@v7 | |
with: | |
result-encoding: string | |
script: | | |
const [owner, repo] = process.env.TARGET_REPO.split('/'); | |
const tags = await github.rest.repos.listTags({ | |
owner, | |
repo, | |
per_page: 10 | |
}); | |
const tagNames = tags.data.map(tag => tag.name).join('\n'); | |
console.log(tagNames); | |
return tagNames; | |
- name: Read known versions | |
id: read_versions | |
run: | | |
versions=$(jq -r '.versions[]' $VERSION_FILE) | |
echo "versions<<EOF" >> $GITHUB_OUTPUT | |
echo "$versions" >> $GITHUB_OUTPUT | |
echo "EOF" >> $GITHUB_OUTPUT | |
- name: Determine new versions | |
id: new_versions | |
run: | | |
target_releases="${{ steps.get_releases.outputs.result }}" | |
known_versions="${{ steps.read_versions.outputs.versions }}" | |
new_versions=() | |
for version in $target_releases; do | |
if ! echo "$known_versions" | grep -qx "$version"; then | |
new_versions+=("$version") | |
fi | |
done | |
if [ ${#new_versions[@]} -ne 0 ]; then | |
echo "new_versions=${new_versions[*]}" >> $GITHUB_OUTPUT | |
fi | |
- name: Install dependencies | |
if: steps.new_versions.outputs.new_versions != '' | |
run: npm ci | |
- name: Pack and sync new versions | |
if: steps.new_versions.outputs.new_versions != '' | |
env: | |
R2_ENDPOINT_URL: https://621480c42e70995622a2d0a86bb7751c.r2.cloudflarestorage.com | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
run: | | |
new_versions=(${{ steps.new_versions.outputs.new_versions }}) | |
for version in "${new_versions[@]}"; do | |
npm run -w packages/packer pack $version | |
npm run -w packages/packer sync $version | |
done | |
- name: Update version.json | |
if: steps.new_versions.outputs.new_versions != '' | |
env: | |
R2_ENDPOINT_URL: https://621480c42e70995622a2d0a86bb7751c.r2.cloudflarestorage.com | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
run: | | |
new_versions=(${{ steps.new_versions.outputs.new_versions }}) | |
known_versions="${{ steps.read_versions.outputs.versions }}" | |
for version in "${new_versions[@]}"; do | |
known_versions=$(echo "$known_versions" | sed "1s/^/\"$version\",\n/") | |
done | |
jq --argjson new_versions "$(printf '%s\n' "${new_versions[@]}" | jq -R . | jq -s .)" '.versions = ($new_versions + .versions)' $VERSION_FILE > tmp.json && mv tmp.json $VERSION_FILE | |
head_version=${new_versions[0]} | |
jq --arg head "$head_version" '.head = $head' $VERSION_FILE > tmp.json && mv tmp.json $VERSION_FILE | |
cat $VERSION_FILE | |
aws s3 cp --region auto --endpoint-url ${R2_ENDPOINT_URL} version.json s3://pob-web/version.json | |
- name: Commit changes | |
if: steps.new_versions.outputs.new_versions != '' | |
env: | |
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} | |
run: | | |
git config user.name "atty303-bot[bot]" | |
git config user.email "atty303-bot[bot]@users.noreply.github.com" | |
git add $VERSION_FILE | |
git commit -m "Update version.json with new releases: ${{ steps.new_versions.outputs.new_versions }}" | |
git push |