Skip to content

Instantly share code, notes, and snippets.

@Shadowbeetle
Created January 25, 2024 13:50
Show Gist options
  • Save Shadowbeetle/101e75a0da35123f0d97cff1223c1bbc to your computer and use it in GitHub Desktop.
Save Shadowbeetle/101e75a0da35123f0d97cff1223c1bbc to your computer and use it in GitHub Desktop.
Update po files in a Phoenix repo when commits are pushed to master
name: Update po files
on:
push:
branches:
- "master"
workflow_dispatch:
jobs:
update-po-files:
runs-on: ubuntu-latest
env:
ELIXIR_VERSION: 1.16.0
OTP_VERSION: 26
steps:
- uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
- uses: erlef/setup-beam@v1
with:
otp-version: ${{env.OTP_VERSION}}
elixir-version: ${{env.ELIXIR_VERSION}}
- name: Install dependencies
run: "mix deps.get"
- name: Run gettext commands
run: |
mix gettext.extract
mix gettext.merge priv/gettext
- name: Commit and push changes
# If we cannot commit, we just exit 0, as it mostly means there are were no po file updates
# and this is not a crucial task anyway, so it's better to get false positive runs than be
# alerted about false negatives. It's not worth the time to handle the errrors in a more
# granular manner.
run: |
git config user.name "GitHub Actions"
git config user.email "github-actions@github.com"
git add .
git commit -m "update gettext po files" || exit 0
git push https://${{ secrets.GH_ACTION_ACCESS_TOKEN }}@github.com/{ORG_NAME}/{REPO_NAME}.git HEAD:master
@Shadowbeetle
Copy link
Author

Shadowbeetle commented Jan 25, 2024

To create a fine-grained Personal Access Token (PAT):

  1. Go to your GitHub account settings.

  2. Click on "Developer settings".

  3. Click on "Personal access tokens". "Pick Fine-grained tokens"

  4. Click on "Generate new token".

  5. Give your token a descriptive name.

  6. Set the Expiration of the token (Defaults to 30 days).

  7. Under "Repository Access", select "Only select repositories" and choose the specific repository you want to work with.

  8. Under "Permissions", scroll down to "Contents" and select "Read and write" permission.

  9. Click on "Generate token" at the bottom of the page.

  10. Save the token somewhere safe. That's the last time you see it.

It's a bit counterintuitive that permission for pushing to a repo is set by the "Content" policy, but if you read the description, it becomes obvious that's the one you need:

Repository contents, commits, branches, downloads, releases, and merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment