Merge pull request #28 from trueberryless-org/update-template-files #39
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: Publish | |
on: | |
push: | |
branches: [main] | |
workflow_dispatch: | |
# Automatically cancel in-progress actions on the same branch | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }} | |
cancel-in-progress: true | |
env: | |
REGISTRY: docker.io | |
IMAGE_OWNER: trueberryless | |
IMAGE_NAME: starlight-plugin-show-latest-version | |
NODE_VERSION: 20 | |
jobs: | |
changes: | |
name: Filter | |
runs-on: ubuntu-latest | |
outputs: | |
starlight-plugin-show-latest-version: ${{ steps.filter.outputs.starlight-plugin-show-latest-version }} | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v4 | |
- uses: dorny/paths-filter@v3 | |
id: filter | |
with: | |
filters: | | |
starlight-plugin-show-latest-version: | |
- 'packages/starlight-plugin-show-latest-version/**' | |
changesets: | |
name: Changesets | |
runs-on: ubuntu-latest | |
outputs: | |
hasChangesets: ${{ steps.changesets.outputs.hasChangesets }} | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- name: Generate GitHub App token | |
id: generate_token | |
uses: tibdex/github-app-token@v2.1.0 | |
with: | |
app_id: ${{ secrets.BOT_APP_ID }} | |
private_key: ${{ secrets.BOT_PRIVATE_KEY }} | |
- name: Checkout Repo | |
uses: actions/checkout@v4 | |
- name: Setup PNPM | |
uses: pnpm/action-setup@v3 | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
cache: "pnpm" | |
- name: Install Dependencies | |
run: pnpm i | |
- name: Create Release Pull Request | |
id: changesets | |
uses: changesets/action@v1 | |
with: | |
commit: "[ci] release" | |
title: "[ci] release" | |
env: | |
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
image-tag: | |
name: Image Tag | |
runs-on: ubuntu-latest | |
outputs: | |
IMAGE_TAG: ${{ env.IMAGE_TAG }} | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v4 | |
- name: Read version from package.json | |
id: get_version | |
run: | | |
VERSION=$(jq -r '.version' packages/starlight-plugin-show-latest-version/package.json) | |
echo "IMAGE_TAG=$VERSION" >> $GITHUB_ENV | |
publish: | |
needs: [changes, changesets, image-tag] | |
if: > | |
( | |
needs.changesets.outputs.hasChangesets == 'false' && | |
( | |
contains(github.event.head_commit.message, 'deploy') || | |
contains(github.event.head_commit.message, '[ci] release') | |
) | |
) || | |
github.event_name == 'workflow_dispatch' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
id-token: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup PNPM | |
uses: pnpm/action-setup@v3 | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
cache: "pnpm" | |
registry-url: "https://registry.npmjs.org" | |
- name: Install Dependencies | |
run: pnpm i | |
- run: | | |
cd packages/starlight-plugin-show-latest-version | |
npm publish --provenance --access public | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
release: | |
name: Release | |
needs: [image-tag, publish] | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v4 | |
- id: extract-changelog | |
uses: sean0x42/markdown-extract@v2.1.0 | |
with: | |
file: packages/starlight-plugin-show-latest-version/CHANGELOG.md | |
pattern: ${{ needs.image-tag.outputs.IMAGE_TAG }} | |
- uses: ncipollo/release-action@v1 | |
id: create_release | |
with: | |
tag: ${{ env.IMAGE_NAME }}@${{ needs.image-tag.outputs.IMAGE_TAG }} | |
makeLatest: true | |
body: ${{ steps.extract-changelog.outputs.markdown }} | |
skipIfReleaseExists: true | |
- name: Check if release was created | |
id: check_release | |
run: | | |
if [ -z "${{ steps.create_release.outputs.html_url }}" ]; then | |
echo "RELEASE_SKIPPED=true" >> $GITHUB_ENV | |
else | |
echo "RELEASE_SKIPPED=false" >> $GITHUB_ENV | |
fi | |
- name: Discord notification | |
if: env.RELEASE_SKIPPED == 'false' | |
env: | |
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }} | |
uses: Ilshidur/action-discord@0.3.2 | |
with: | |
args: | | |
# ${{ env.IMAGE_NAME }}@${{ needs.image-tag.outputs.IMAGE_TAG }} | |
${{ steps.extract-changelog.outputs.markdown }} |