Add recommend
to Discussion service (#143)
#22
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: Create release PR or Release Packages | |
on: | |
push: | |
branches: | |
- main | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
version_check: | |
runs-on: ubuntu-latest | |
outputs: | |
versionChanged: ${{ steps.get_version.outputs.versionChanged }} | |
version: ${{ steps.get_version.outputs.version }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
# Get the latest 2 commits so we can compare the versions in package.json | |
fetch-depth: 2 | |
- name: Get version | |
id: get_version | |
run: | | |
PREV_VERSION=$(git checkout -q HEAD^ && npm pkg get version && git switch -q -) | |
CURR_VERSION=$(npm pkg get version) | |
echo "versionChanged=$(if [ "$PREV_VERSION" = "$CURR_VERSION" ]; then echo "false"; else echo "true"; fi)" >> $GITHUB_OUTPUT | |
echo "version=v$(echo $CURR_VERSION | xargs)" >> $GITHUB_OUTPUT | |
changesets_release_pr: | |
runs-on: ubuntu-latest | |
outputs: | |
hasChangesets: ${{ steps.changesets.outputs.hasChangesets }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
cache: npm | |
node-version-file: ".nvmrc" | |
- run: npm install | |
- uses: changesets/action@v1 | |
id: changesets | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
npm_release: | |
runs-on: ubuntu-latest | |
needs: [changesets_release_pr, version_check] | |
if: needs.changesets_release_pr.outputs.hasChangesets == 'false' && needs.version_check.outputs.versionChanged == 'true' | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
cache: npm | |
node-version-file: ".nvmrc" | |
- run: npm install | |
- name: Publish NPM | |
run: ./gen-typescript.sh release ${VERSION} | |
env: | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
VERSION: ${{ needs.version_check.outputs.version }} | |
native_release: | |
runs-on: ubuntu-latest | |
needs: [changesets_release_pr, version_check] | |
if: needs.changesets_release_pr.outputs.hasChangesets == 'false' && needs.version_check.outputs.versionChanged == 'true' | |
strategy: | |
fail-fast: false # do not cancel other in progress jobs if any single one fails | |
matrix: | |
include: | |
- platform: android | |
repository: bridget-android | |
- platform: ios | |
repository: bridget-swift | |
steps: | |
- uses: actions/create-github-app-token@v1 | |
id: app-token | |
with: | |
app-id: ${{ vars.APP_ID }} | |
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }} | |
owner: guardian | |
repositories: ${{ format('bridget,{0}', matrix.repository) }} # e.g "bridget,bridget-swift" | |
- uses: actions/checkout@v4 | |
- name: Release | |
uses: ./.github/actions/generate-native-package | |
with: | |
access_token: ${{ steps.app-token.outputs.token }} | |
platform: ${{ matrix.platform }} | |
release_type: "release" | |
version: ${{ needs.version_check.outputs.version }} | |
create_github_release: | |
name: Create GitHub Release | |
runs-on: ubuntu-latest | |
if: needs.changesets_release_pr.outputs.hasChangesets == 'false' && needs.version_check.outputs.versionChanged == 'true' | |
needs: [changesets_release_pr, version_check, npm_release, native_release] | |
steps: | |
- uses: actions/checkout@v4 | |
# This tag will get pushed by the Changesets action in the next step! | |
- name: Tag local repository | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
git tag -m "$VERSION" $VERSION | |
env: | |
VERSION: ${{ needs.version_check.outputs.version }} | |
- name: Create release in GitHub | |
uses: changesets/action@v1 | |
with: | |
# The actual release process has already completed in jobs npm_release and native_release | |
# Changesets will only create the tags/release if it sees "New tag:" in the publish command's output | |
# See https://github.com/changesets/action/blob/63ffd93140be6000b385d611d886a82c86214719/src/run.ts#L176 | |
publish: "echo 'New tag:'" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |