From 3e663e68f208ccebad415244c11cbef5077a636c Mon Sep 17 00:00:00 2001 From: Remco Tolsma <869674+remcotolsma@users.noreply.github.com> Date: Mon, 24 Jul 2023 12:37:54 +0200 Subject: [PATCH] Add release script. --- .github/scripts/README.md | 6 + .github/scripts/release.php | 269 ++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 20 +++ 3 files changed, 295 insertions(+) create mode 100644 .github/scripts/README.md create mode 100644 .github/scripts/release.php create mode 100644 .github/workflows/release.yml diff --git a/.github/scripts/README.md b/.github/scripts/README.md new file mode 100644 index 0000000..9ddbec3 --- /dev/null +++ b/.github/scripts/README.md @@ -0,0 +1,6 @@ +# ACF PRO releaser + +## Links + +- https://connect.advancedcustomfields.com/ +- https://connect.advancedcustomfields.com/v2/plugins/update-check diff --git a/.github/scripts/release.php b/.github/scripts/release.php new file mode 100644 index 0000000..49d15fc --- /dev/null +++ b/.github/scripts/release.php @@ -0,0 +1,269 @@ + [ + 'id' => 'pro', + 'key' => $acf_pro_license, + 'slug' => 'advanced-custom-fields-pro', + 'basename' => $basename, + 'version' => '1.0.0', + ] +]; + +$data_wp = [ + 'wp_name' => 'acf', +]; + +$data_acf = [ + 'acf_version' => '1.0.0', + 'acf_pro' => true, + 'block_count' => 0, +]; + +$data = run( + sprintf( + 'curl --data %s --data %s --data %s --request POST %s', + escapeshellarg( 'plugins=' . json_encode( $data_plugins ) ), + escapeshellarg( 'wp=' . json_encode( $data_wp ) ), + escapeshellarg( 'acf=' . json_encode( $data_acf ) ), + escapeshellarg( $url ) + ) +); + +$result = json_decode( $data ); + +var_dump( $result ); + +if ( ! is_object( $result ) ) { + throw new Exception( + sprintf( + 'Unknow response from: %s.', + $url + ) + ); + + exit( 1 ); +} + +if ( ! property_exists( $result, 'plugins' ) ) { + echo 'No plugins'; + + exit( 1 ); +} + +$plugins = $result->plugins; + +if ( ! property_exists( $plugins, $basename ) ) { + echo 'No plugin'; + + exit( 1 ); +} + +$plugin = $plugins->{$basename}; + +if ( ! property_exists( $plugin, 'new_version' ) ) { + echo 'Unknown version'; + + exit( 1 ); +} + +$version = $plugin->new_version; + +$url = $plugin->package; + +line( + sprintf( + 'ACF Version: %s', + $version + ) +); + +line( + sprintf( + 'ACF ZIP URL: %s', + $url + ) +); + +line( '::endgroup::' ); + +/** + * Files. + */ +$work_dir = tempnam( sys_get_temp_dir(), '' ); + +unlink( $work_dir ); + +mkdir( $work_dir ); + +$archives_dir = $work_dir . '/archives'; +$plugins_dir = $work_dir . '/plugins'; + +mkdir( $archives_dir ); +mkdir( $plugins_dir ); + +$plugin_dir = $plugins_dir . '/advanced-custom-fields-pro'; + +$zip_file = $archives_dir . '/advanced-custom-fields-pro-' . $version . '.zip'; + +/** + * Download ZIP. + */ +line( '::group::Download ACF' ); + +run( + sprintf( + 'curl %s --output %s', + escapeshellarg( $url ), + $zip_file + ) +); + +line( '::endgroup::' ); + +/** + * Unzip. + */ +line( '::group::Unzip ACF' ); + +run( + sprintf( + 'unzip %s -d %s', + escapeshellarg( $zip_file ), + escapeshellarg( $plugins_dir ) + ) +); + +line( '::endgroup::' ); + +/** + * Synchronize. + * + * @link http://stackoverflow.com/a/14789400 + * @link http://askubuntu.com/a/476048 + */ +line( '::group::Synchronize ACF' ); + +run( + sprintf( + 'rsync --archive --delete-before --exclude=%s --exclude=%s --exclude=%s --verbose %s %s', + escapeshellarg( '.git' ), + escapeshellarg( '.github' ), + escapeshellarg( 'composer.json' ), + escapeshellarg( $plugin_dir . '/' ), + escapeshellarg( '.' ) + ) +); + +line( '::endgroup::' ); +exit; +/** + * Git user. + * + * @link https://github.com/roots/wordpress/blob/13ba8c17c80f5c832f29cf4c2960b11489949d5f/bin/update-repo.php#L62-L67 + */ +run( + sprintf( + 'git config user.email %s', + escapeshellarg( 'support@advancedcustomfields.com' ) + ) +); + +run( + sprintf( + 'git config user.name %s', + escapeshellarg( 'ACF' ) + ) +); + +/** + * Git commit. + * + * @link https://git-scm.com/docs/git-commit + */ +run( 'git add --all' ); + +run( + sprintf( + 'git commit --all -m %s', + escapeshellarg( + sprintf( + 'Updates to %s', + $version + ) + ) + ) +); + +run( 'git config --unset user.email' ); +run( 'git config --unset user.name' ); + +run( 'gh auth status' ); + +run( 'git push origin main' ); + +/** + * GitHub release view. + */ +$tag = 'v' . $version; + +run( + sprintf( + 'gh release view %s', + $tag + ), + $result_code +); + +$release_not_found = ( 1 === $result_code ); + +/** + * GitHub release. + * + * @todo https://memberpress.com/wp-json/wp/v2/pages?slug=change-log + * @link https://cli.github.com/manual/gh_release_create + */ +if ( $release_not_found ) { + run( + sprintf( + 'gh release create %s %s --title %s', + $tag, + $zip_file, + $version + ) + ); +} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..002bbe3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,20 @@ +name: Release + +on: + schedule: + - cron: '0 10 * * *' + workflow_dispatch: + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Release + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + ACF_PRO_LICENSE: ${{ secrets.ACF_PRO_LICENSE }} + run: php .github/scripts/release.php