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: add update-package workflow #144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
86 changes: 86 additions & 0 deletions .github/workflows/update-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Update package

on:
workflow_dispatch:
inputs:
package:
type: choice
required: true
options:
- etf2l_configs

version:
type: string
required: true

jobs:
update-package:
runs-on: ubuntu-latest

permissions:
contents: write
pull-requests: write

steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.ACTIONS_BOT_TOKEN }}

- name: Set git identity
run: |
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git config --global user.name 'github-actions[bot]'

- name: Replace version string
run: |
case ${{ inputs.package }} in
etf2l_configs)
sed -i 's/ETF2L_CONFIGS_VERSION=.*/ETF2L_CONFIGS_VERSION=${{ inputs.version }}/' packages/tf2-competitive/Dockerfile
;;
*)
echo "invalid package"
exit 1
;;
esac

- name: Download new package version and replace its md5
run: |
case ${{ inputs.package }} in
etf2l_configs)
ETF2L_CONFIGS_URL=$(grep -r "ARG ETF2L_CONFIGS" packages/tf2-competitive/Dockerfile | sed -E 's/^ARG\s(.+)=(.+)$/\1="\2"/g' | { eval "$(cat -)"; echo $ETF2L_CONFIGS_URL; })
MD5SUM=$(wget -O - "$ETF2L_CONFIGS_URL" | tee file | md5sum | awk '{print $1}')
sed -i -E 's/^([0-9a-f]+)(\s+)(etf2l_configs.zip)$/'"$MD5SUM"'\2\3/g' packages/tf2-competitive/checksum.md5
echo "package_url=${ETF2L_CONFIGS_URL}" >> "$GITHUB_ENV"
echo "package_md5=${MD5SUM}" >> "$GITHUB_ENV"
;;
*)
echo "invalid package"
exit 1
;;
esac

- name: Generate human-friendly package name
run: |
case ${{ inputs.package }} in
etf2l_configs)
echo "package_name=ETF2L.org gameserver configs" >> "$GITHUB_ENV"
;;
*)
echo "invalid package"
exit 1
;;
esac

- name: Create pull request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "fix(deps): update ${package_name} to version ${{ inputs.version }}"
title: "fix(deps): update ${package_name} to version ${{ inputs.version }}"
body: |
Update [${package_name}](${package_url}) to version ${{ inputs.version }}
MD5: ${package_md5}
branch: update-${{ inputs.package }}-${{ inputs.version }}
delete-branch: true
reviewers: garrappachc