Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Automate releases and check POTFILES.in #1454

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:
- name: Check out xdg-desktop-portal
uses: actions/checkout@v4

- name: Check POTFILES.in
run: .github/workflows/check-potfiles.sh

- name: Check out libportal fork with a similarly named branch
id: libportal-branched
uses: actions/checkout@v4
Expand Down
92 changes: 92 additions & 0 deletions .github/workflows/check-potfiles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/env bash

# FIXME stolen from gnome-control-center, GPLv2
# This project is LGPLv2
# https://gitlab.gnome.org/GNOME/gnome-control-center/-/merge_requests/2269#note_2079291

srcdirs="src document-portal"
uidirs=$srcdirs
desktopdirs=$srcdirs
policydirs=$srcdirs
xmldirs=$srcdirs

# find source files that contain gettext functions with literal or GETTEXT_PACKAGE argument
files=$(grep -lRs --include='*.c' 'gettext *(\("\|GETTEXT_PACKAGE,\)' $srcdirs)

# find source files that contain gettext macros
files="$files "$(grep -lRs --include='*.c' --include='*.h' '[^I_)]_(' $srcdirs)

# find ui files that contain translatable string
files="$files "$(grep -lRis --include='*.ui' 'translatable="[ty1]' $uidirs)

# find .desktop files
files="$files "$(find $desktopdirs -name '*.desktop*')

# find .policy files
files="$files "$(find $policydirs -name '*.policy*')

# find .xml.in and .gschema.xml files
files="$files "$(find $xmldirs -not -name '*.gresource.xml*' \
-name '*.xml.in*' -o \
-name '*.gschema.xml')

# filter out excluded files
if [ -f po/POTFILES.skip ]; then
files=$(for f in $files; do
! grep -q "^$f" po/POTFILES.skip && echo "$f"
done)
fi

# find those that aren't listed in POTFILES.in
missing=$(for f in $files; do
! grep -q "^$f" po/POTFILES.in && echo "$f"
done)

# find those that are listed in POTFILES.in but do not contain translatable strings
invalid=$(while IFS= read -r f; do
! grep -q "$f" <<< "$files" && echo "$f"
done < <(grep '^[^#]' po/POTFILES.in))

# find out if POTFILES.in is sorted correctly, ignoring empty lines
sorted=$(grep '^[^#]' po/POTFILES.in | \
LC_ALL=en_US.UTF-8 sort -cu 2>&1 >/dev/null | \
awk -F ': *' '{print $5}')

if [ ${#missing} -eq 0 ] && [ ${#invalid} -eq 0 ] && [ ${#sorted} -eq 0 ]; then
exit 0
fi

if [ ${#missing} -ne 0 ]; then
cat >&2 << EOT

The following files are missing from po/POTFILES.in or po/POTFILES.skip:

EOT
for f in $missing; do
echo " $f" >&2
done
fi

if [ ${#invalid} -ne 0 ]; then
cat >&2 << EOT

The following files are in po/POTFILES.in but are missing or not translatable:

EOT
for f in $invalid; do
echo " $f" >&2
done
fi

if [ ${#sorted} -ne 0 ]; then
cat >&2 << EOT

The following file is not sorted properly in po/POTFILES.in:

EOT
echo " $sorted" >&2
fi

echo >&2

exit 1
101 changes: 101 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Release new version

on:
workflow_dispatch:
inputs:
version:
description: "Release version (MAJOR.MINOR.PATCH, default: extracted from NEWS)"
preRelease:
description: "Is this a pre-release? (true/false, default: true if release version minor number is odd)"
dryRun:
description: "Dry Run (true/false, default: true)"
default: true

jobs:
build-container:
uses: ./.github/workflows/container.yml
permissions:
packages: write

release:
name: Build and publish a release
runs-on: ubuntu-latest
needs: build-container
permissions:
contents: write

container:
image: ${{ needs.build-container.outputs.image }}
options: ${{ needs.build-container.outputs.image_options }}

steps:
- name: Configure git user
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global --add safe.directory $GITHUB_WORKSPACE

- name: Checkout the repository
uses: actions/checkout@v4

- name: Update translation files
if: ${{ !fromJSON(github.event.inputs.dryRun) }}
run: |
meson setup . _build
meson compile -C _build/ xdg-desktop-portal-update-po
git add po/*po
git commit -m "Update po files"
git push
git clean -fxd

- name: Build xdg-desktop-portal
if: ${{ !fromJSON(github.event.inputs.dryRun) }}
run: |
meson setup . _build
meson dist -C _build

- name: Extract release information
env:
releaseVersion: ${{ github.event.inputs.version }}
preRelease: ${{ github.event.inputs.preRelease }}
run: |
# Extract the release version
if [ -z $releaseVersion ]; then
releaseVersion=`perl -0777nE 'print $& if /(?<=Changes in ).*/' NEWS`
fi
echo "releaseVersion=$releaseVersion" | tee -a $GITHUB_ENV

# Extract the changelog
{
echo "releaseChangelog<<EOF"
perl -0777nE 'print $& if /(?<=\n\n).*?(?=\n\n)/sg' NEWS
echo "\nEOF"
} | tee -a $GITHUB_ENV

# Check if version is a pre-release
if [ -z $preRelease ]; then
preRelease=$((`echo $releaseVersion | cut -d '.' -f2` % 2))
fi
{
echo -n "preRelease="
if [ $preRelease = 1 ] || [ $preRelease = "true" ]; then
echo "true";
else
echo "false";
fi
} | tee -a $GITHUB_ENV

- name: Tag release
if: ${{ !fromJSON(github.event.inputs.dryRun) }}
run: |
git tag $releaseVersion
git push --tags

- name: Create release
if: ${{ !fromJSON(github.event.inputs.dryRun) }}
uses: ncipollo/[email protected]
with:
tag: ${{ env.releaseVersion }}
body: ${{ env.releaseChangelog }}
prerelease: ${{ env.preRelease }}
artifacts: _build/meson-dist/*
26 changes: 7 additions & 19 deletions RELEASE_HOWTO.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
# Steps for doing a xdg-desktop-portal release

- git clean -fxd
- meson setup . _build && meson compile -C _build/ xdg-desktop-portal-update-po
- git add po/*po && git commit -m "Update po files"
- git clean -fxd
- add content to NEWS
- git commit -m <version>
- git push origin main
- meson setup . _build -Ddocbook-docs=enabled
- meson dist -C _build
- git tag <version>
- git push origin refs/tags/<version>
- upload tarball to github as release
- edit release, copy NEWS section in
- update portal api docs in the gh-pages branch
- bump version in meson.build
- git commit -m "Post-release version bump"
- git push origin main
- Update SECURITY.md if this is a new stable release
- Update .github/ISSUE_TEMPLATE/bug-report.yml if this is a new stable release
- Make sure the version in `meson.build` is correct
- Add your changelog to the `NEWS` file
- Run the "Release new version" GitHub Action
- The options are taken from the last `NEWS` entry by default, you may override them if needed
- Bump version in `meson.build`
- Update `SECURITY.md` if this is a new stable release
- Update `.github/ISSUE_TEMPLATE/bug-report.yml` if this is a new stable release
Loading